Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

COPY returns ERRORLEVEL 2

Mar
6
0
When copying a directory with only subdirectories, COPY return an ERRORLEVEL 2 as seen in the clip below. When directory "Appendix of SDD" is copied, the error occurs. Is there a way to force the COPY command to return a value of zero? Normally this is not an issue, but when COPY is called from a Python script, the program crashes.

Capture.JPG
 
When copying a directory with only subdirectories, COPY return an ERRORLEVEL 2 as seen in the clip below. When directory "Appendix of SDD" is copied, the error occurs. Is there a way to force the COPY command to return a value of zero? Normally this is not an issue, but when COPY is called from a Python script, the program crashes.

View attachment 1008
I would have a workaround only ... you could expanding your command line as follow:

Code:
echo tmp > "o:\Test\test.tmp" & copy /D /F /H /J /K /V /Y /Z /S /MD /UF "o:\Test\" "d:\Projects\Test\" & del "o:\Test\test.tmp" & del "d:\Projects\Test\test.tmp" & echo %_?


Then the errorlevel should be 0 ... as you can see from my test example ...

Code:
[D:\_Temp_]echo tmp > "d:\_Temp_\test\test.tmp" & copy /D /F /H /J /K /V /Y /Z /S /MD /UF "d:\_Temp_\test\" "d:\_Tests_\" & del "d:\_Temp_\test\test.tmp" & del "d:\_Tests_\test.tmp" & ECHO %_?
D:\_Temp_\test\test.tmp => D:\_Tests_\test.tmp
     1 Datei kopiert
Lösche D:\_Temp_\test\test.tmp
     1 Datei gelöscht
Lösche D:\_Tests_\test.tmp
     1 Datei gelöscht
0


BTW: I have corrected the "/F/" param to "/F" because it's a typo?! However: should be not related to the errorlevel ...
 
Last edited:
WAD - COPY will return an error if it didn't copy any files. You can work around it by adding the /U option (or /C, depending on your circumstances). An attempted update (/U) isn't considered an error if the files are the same.
Does the /UF option the function in a similar manner? My command is using /UF.

ie: copy /D /F /H /J /K /V /Y /Z /S /MD /UF "o:\Test\" "d:\Projects\Test\"
 

Similar threads

Replies
7
Views
2K
Back
Top