COPY returns ERRORLEVEL 2

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Mar 3, 2009
6
0
#1
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
 
#2
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:
Mar 3, 2009
6
0
#4
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\"
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#5
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\"
No, /UF does not turn off the "file not found" error, though perhaps it should. I've added it to the list for a future version.

Are you actually still copying to/from FAT volumes?