I have the following batch file to download backups from our server:
@echo off
d:
cd \DBBackups
curl -u user:password https://example.com/Backups/list.php?p=anotherpassword >list.txt
SETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ list.txt"`) do (
echo =========================================
set "var=%%a"
SETLOCAL EnableDelayedExpansion
set "var=!var:*:=!"
set "tmp=%%a"
set "_tempvar=YesYes"
if !tmp:~-3!==tar set "_tempvar=1"
if !tmp:~-3!==bak set "_tempvar=1"
if !_tempvar! EQU 1 (
if exist !var! (
echo !var! has already been downloaded
) else (
echo Downloading !var!
)
if not exist !var! wget --no-check-certificate --user=user --password=yap https://www.example.com/Backups/!var!)
)
ENDLOCAL
)
c:
echo "Drive changed!"
The file receives a list of files (one file per line) and saves them to list.txt. Then it reads each line and downloads the file. At the end, changing the drive back to c: fails.
I thought it maybe that the ERRORLEVEL is being set to greater than 0. So I've tried the solutions presented here including "cmd /c "exit /b 0"", "cd .", and "ver > nul" but they don't work. The echo at the end "Drive changed!" 0 does print.
Any suggestions welcome.