I have the following batch file contents:
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=
Given it does not exist the file in in cc_server
it then falls through the backups
machine where it exists.
The problem is: if I run the script, I will see a whole bunch of
SET NewestDir=
lines, and after:
File Not Found
Press any key to continue . . .
which corresponds to the PAUSE
command line.
I know the files exist there, as the next paragraph will make it clear.
If I copy the instructions of the relevant part and replace the %%
occurrences by %
as follows:
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
)
and run it directly in the command prompt, the problem does not occur, and the NewestFile
variable will be set.
What am I wrong doing?