How to Log error number from robocopy
I have the below code to copy a file and log some information. I would like to add to this log the error number produced by robocopy, what ever it is. I've tried several things without luck and am looking for suggestions on this.
Robocopy "D:\CSV\Test csv files\Friday" "D:\CSV\Test csv files\Test1" *.csv /njh /njs /ts /np /ns /log+:D:\CSV\Copy_Log_Files\Log.txt
Robocopy logs an error into the log file, but that's a bit hidden inside the text. Here's an example of how it looks like:
2023/04/06 09:19:13 ERROR 32 (0x00000020) Copying File .\sqlite3\db.lock The process cannot access the file because it is being used by another process.
So you could parse for that error. But if you want to get its exit status (for a quick status check instead of fully parsing the log), I suggest to add a simple echo to the call:
robocopy "D:\CSV\Test csv files\Friday" "D:\CSV\Test csv files\Test1" *.csv /njh /njs /ts /np /ns /log+:D:\CSV\Copy_Log_Files\Log.txt
echo Robocopy exit: %ERRORLEVEL% >>D:\CSV\Copy_Log_Files\Log.txt
You'll have to wrap this in a batch file if you're planning to launch it via Task.