|Putting in the double lines "||" results in the new folder being created, but nothing is copied over, and the batch closed immediately.|
I spent all Saturday searching the internet for information on xcopy, IF statements and errorlevels, and tried countless batch variations. What I currently have is as follows:
set /p INPUT= Enter PREVIOUS Date (ddmmyyyy) for which you want to create an ARCHIVE folder:
xcopy i:\*.* h:\archive\graphics\%INPUT% /D/E/R/I/K/-Y/exclude:i:\ErrorMssg\omit.txt
if errorlevel 5 goto diskerror
if errorlevel 4 goto copyerror
if errorlevel 2 goto copyterminated
if errorlevel 1 goto nofiles
if errorlevel 0 goto success
xcopy i:\ErrorMssg\DiskError.rtf h:\archive\graphics\%INPUT%
echo A DISK WRITE ERROR OCCURRED! STOPPING Backup Procedure.
xcopy i:\ErrorMssg\CopyError.rtf h:\archive\graphics\%INPUT%
echo The Archive Drive is FULL! STOPPING Backup Procedure.
echo Ctrl + C was pressed, Terminating the Archive Procedure.
echo There were NO FILES to Archive.
echo y | rd /s/q i:\DailyWork
echo y | del i:\Clients.xls
echo The backup was successful.
I think that the problem lies with the ErrorLevel, which for some reason is not being recognized and subsequently the GOTO statements are not working correctly. So, for example, when I run a test where there is nothing but the ERRORMSSG folder on the i:/ drive (which is excluded in the copy process), the batch file in it's current incarnation should encounter an ErrorLevel of 1, as there are no files to copy over, resulting in the statement "There were NO FILES to Archive." showing up in the batch window on-screen. However, instead what one sees on the screen in the batch pop-up window is the following, when one runs the batch:
Enter PREVIOUS Date (ddmmyyyy) for which you want to create an ARCHIVE folder:
0 file(s) copied
The system cannot find the file specified.
Could not find i:\Clients.xls
The backup was successful.
Press any key to continue ...
The batch does create the new folder, in this example titled 20082011, and only states that it cannot find the file "Clients.xls", as opposed to not finding both the "Clients.xls" file and "DailyWork" folder. Then, rather than returning the statement "There were NO FILES to Archive." from :nofiles as the batch should, instead it returns the statement "The backup was successful." from :success, which is incorrect.
According to what I've read, the ErrorLevel statements need to be in descending order 5, 4, 2, 1, 0 (as opposed to ascending order) for it to work properly. Also, that the Exit Code definitions are as follows:
5 - Disk write error occurred.
4 - Various errors including insufficient memory or disk space, an invalid drive name, or invalid syntax.
2 - The user pressed Ctrl+C to terminate xcopy.
1 - No files were found to copy.
0 - Files were copied without error.
I've tried variations with the Comparison Operators; for example both == and EQU in the IF statement, but it doesn't make any difference. I've also tried both both using and not using a preceeding colon in the GOTO statement:
"if errorlevel 5 goto :diskerror" and if "errorlevel 5 goto diskerror"
as I've seen both ways used in tutorial examples, but my batch still doesn't work correctly.
I am at a total loss as to how to proceed. It's so frustrating.
~ Sally :(