您好有一个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