您好有一個for循環,我用來獲取輸入的驅動器循環通過,爲每個驅動器循環通過文件中的條目,這一切工作。但後來我試圖做的是從文件中找到條目(這是一個文件名和路徑沒有驅動器號和第一個文件夾(父文件夾名爲%_TAG%)問題與Windows批處理腳本 - 替換
好吧,到目前爲止好,現在我想要做的是用ar替換文件的擴展名(* .w或* .p或* .cls必須成爲* .r)
但由於某種原因,我的命令不起作用(set str =! STR:.W = .R)我曾嘗試更換與%
我曾嘗試過各種東西,仍然卡住這是我的完整的批處理文件,它以局部的路徑和文件列表讀取一個文件!。我甚至嘗試使用一個函數來重命名
:bof
@echo on
cls
setlocal enabledelayedexpansion
:init
set _TAG=TST
set /p _INFILE="Enter Filename to use for investigation: "
set _INFILE=%CD%\%_INFILE%
set /p _TAG="To which environment did you deploy? (TST/LIV): "
if /i "%_TAG%"=="LIV" (
set _drive=M O P R S Y X
) else (
set _drive=M T X
)
:confirm
echo We will use code in the: %_TAG% folder and file: %_INFILE% and drives: %_drive%
set /p _continue="Do you wish to continue (Y/N): "
if /i "%_continue%"=="N" goto :eof
echo We will use code in the: %_TAG% folder and file: %_INFILE% and drives: %_drive% 1>> %_INFILE%.%_TAG%.rlog 2>&1
:dowork
for %%j in (%_drive%) do (
echo ...
echo investigating: %%j:\%_TAG%\ 1>> %_INFILE%.%_TAG%.rlog 2>&1
%%j:
cd %%j:\%_TAG%\
for /f %%i in (%_INFILE%) DO (
set "string=%%i"
call:mySetPathFunc !string! "/" "\"
call:mySetPathFunc !string! ".w" ".r"
call:mySetPathFunc !string! ".p" ".r"
call:mySetPathFunc !string! ".cls" ".r"
if exist %%j:\%_TAG%\!string! (
echo I found you in correct folder 1>> %_INFILE%.%_TAG%.rlog 2>&1
) else (
echo I did not find you in correct folder 1>> %_INFILE%.%_TAG%.rlog 2>&1
)
call:mySetPathFunc !string! "cbsrc" "tty"
call:mySetPathFunc !string! "hotfix" "tty"
if exist %%j:\%_TAG%\%%string%% (
echo I found you in tty 1>> %_INFILE%.%_TAG%.rlog 2>&1
) else (
echo I did not find you in tty 1>> %_INFILE%.%_TAG%.rlog 2>&1
)
)
)
:eof
ECHO Done used - tag: %_TAG% and used file: %_INFILE% to drive %_drive%
ECHO Done used - tag: %_TAG% and used file: %_INFILE% to drive %_drive% 1>> %_INFILE%.%_TAG%.rlog 2>&1
timeout /t 8 /nobreak > NUL
c:
exit /b
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:mySetPathFunc - passing a variable by reference
echo before %~1 1>> %_INFILE%.%_TAG%.rlog 2>&1
set %~1=%~1:%~2=%~3
echo after %~1 1>> %_INFILE%.%_TAG%.rlog 2>&1
goto:eof
我已經包含了完整的批處理文件,用我最近的更改來嘗試和解決問題,但我仍然沒有得到「string」中的正確值 – AquaAlex