我具有以下批处理文件内容:
REM Newest folder
FOR /F "delims=" %%I IN ('DIR \\cc_server\CruiseControl\TFS_Root\Release\2017.V1\Deploy\Store\Company\MyApp\* /B /O:D /AD') DO SET NewestDir=%%I
REM Newest file of newest folder
IF Defined NewestDir (
FOR /F "delims=" %%I IN ('DIR "\\cc_server\CruiseControl\TFS_Root\Release\2017.V1\Deploy\Store\Company\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.7z" "\\cc_server\CruiseControl\TFS_Root\Release\2017.V1\Deploy\Store\Company\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.zip" /B /O:D /A-D') DO SET NewestFile=%%I
IF Defined NewestFile (
SET ExistsInStore=TRUE
)
) ELSE (
FOR /F "delims=" %%I IN ('DIR \\backups\Builds\Release\2017.V1\MyApp\* /B /O:D /AD') DO SET NewestDir=%%I
IF Defined NewestDir (
FOR /F "delims=" %%J IN ('DIR \\backups\Builds\Release\2017.V1\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.7z \\backups\Builds\Release\2017.V1\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.zip /B /O:D /A-D') DO SET NewestFile=%%J
PAUSE
)
)
IF Defined NewestFile (
IF Defined ExistsInStore (
copy "\\cc_server\CruiseControl\TFS_Root\Release\2017.V1\Deploy\Store\Company\MyApp\%NewestDir%\%NewestFile%" .
) ELSE (
copy "\\backups\Builds\Release\2017.V1\MyApp\%NewestDir%\%NewestFile%" .
)
"C:\Program Files\7-Zip\7z" x "%NewestFile%" -o"MyApp 2017"
del "%NewestFile%"
)
Set NewestDir=
SET NewestFile=
SET ExistsInStore=
如果文件cc_server
中不存在,则该文件将通过存在该文件的backups
机器。
问题是:如果我运行脚本,将会看到一大堆
SET NewestDir=
行以及之后:
File Not Found
Press any key to continue . . .
对应于PAUSE
命令行。
我知道文件存在于此,下一段将使它变得清楚。
如果我复制相关部分的说明,并用%%
替换%
项,如下所示:
FOR /F "delims=" %I IN ('DIR \\backups\Builds\Release\2017.V1\MyApp\* /B /O:D /AD') DO SET NewestDir=%I
IF Defined NewestDir (
FOR /F "delims=" %J IN ('DIR \\backups\Builds\Release\2017.V1\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.7z \\backups\Builds\Release\2017.V1\MyApp\%NewestDir%\[RL]*[x64]*[SuperPro]*.zip /B /O:D /A-D') DO SET NewestFile=%J
)
并直接在命令提示符下运行它,不会发生此问题,并且将设置NewestFile
变量。
我做错了什么?