When I use this code with xcopy the Errorlevel is "0":
Code: Select all
:FileCopied
Echo ~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
set "file="
if not exist "%FileName%" (
set "file=!file!!lf! ? %FileName%"
xcopy /y /f "Z:\%FileName%" "%wkdir%"
Echo %ERRORLEVEL%
IF NOT ERRORLEVEL 1 GOTO FileCopied)
This is what shows in the cmd window:
Code: Select all
C:\Dnload\VNC>Echo ~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
C:\Dnload\VNC>set "file="
C:\Dnload\VNC>if not exist "VNC UltraVNC_1_4_06_X64_Setup.exe" (
set "file=!file!!lf! ? VNC UltraVNC_1_4_06_X64_Setup.exe"
xcopy /y /f "Z:\VNC UltraVNC_1_4_06_X64_Setup.exe" "C:\Dnload\VNC\"
Echo 0
IF NOT ERRORLEVEL 1 GOTO FileCopied
)
Z:\VNC UltraVNC_1_4_06_X64_Setup.exe -> C:\Dnload\VNC\VNC UltraVNC_1_4_06_X64_Setup.exe
1 File(s) copied
0
C:\Dnload\VNC>Echo ~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
C:\Dnload\VNC>set "file="
C:\Dnload\VNC>if not exist "VNC UltraVNC_1_4_06_X64_Setup.exe" (
set "file=!file!!lf! ? VNC UltraVNC_1_4_06_X64_Setup.exe"
xcopy /y /f "Z:\VNC UltraVNC_1_4_06_X64_Setup.exe" "C:\Dnload\VNC\"
Echo 0
IF NOT ERRORLEVEL 1 GOTO FileCopied
)
The code passes FileCopied the first time
The code does copy the file the first time
On the line " IF NOT ERRORLEVEL 1 GOTO FileCopied it does GOTO FileCopied
The second time it goes through FileCopied the "if not exist" skips the code
Which is exactly what I want it to do.
When I use this code with RoboCopy the Errorlevel is "0":
Code: Select all
:FileCopied
Echo ~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
set "file="
if not exist "%FileName%" (
set "file=!file!!lf! ? %FileName%"
robocopy "%IPADDRESS%\Dnload\VNC" "%wkdir%" "%FileName%"
Echo %ERRORLEVEL%
IF NOT ERRORLEVEL 1 GOTO FileCopied)
This is what shows in the cmd window:
Code: Select all
C:\Dnload\VNC>Echo ~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
~*~*~*~*~*~*~*~*~*~*~*~ I passed by FileCopied ~*~*~*~*~*~*~*~*~*~*~*~
C:\Dnload\VNC>set "file="
C:\Dnload\VNC>if not exist "VNC UltraVNC_1_4_06_X64_Setup.exe" (
set "file=!file!!lf! ? VNC UltraVNC_1_4_06_X64_Setup.exe"
robocopy "\\192.168.1.127\Dnload\VNC" "C:\Dnload\VNC" "VNC UltraVNC_1_4_06_X64_Setup.exe"
Echo 0
IF NOT ERRORLEVEL 1 GOTO FileCopied
)
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Thursday, October 12, 2023 2:38:38 PM
Source : \\192.168.1.127\Dnload\VNC\
Dest : C:\Dnload\VNC\
Files : VNC UltraVNC_1_4_06_X64_Setup.exe
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
1 \\192.168.1.127\Dnload\VNC\
100% New File 5.0 m VNC UltraVNC_1_4_06_X64_Setup.exe
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 5.08 m 5.08 m 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 11026743 Bytes/sec.
Speed : 630.955 MegaBytes/min.
Ended : Thursday, October 12, 2023 2:38:39 PM
0
The code passes FileCopied the first time
The code does copy the file the first time
On the line " IF NOT ERRORLEVEL 1 GOTO FileCopied it does NOT GOTO FileCopied
The ERRORLEVEL = 0
The code continues in the script
Which is NOT what I want it to do.
Why doesn't it GOTO FileCopied with RoboCopy like it does with XCopy?