I don't know if a batchfile is a proper solution to this problem, but I'll describe what I need to do and what I've done so far.
I use a batch file triggering Robocopy and then Blat to send logfiles of a daily file copy task to a target address. Instead of sending the logfiles daily, regardless of success or failure of the copy, I'd like to ONLY send the logfile if a failure is present in the log.
An example of my existing batch is below. Please note, I am not a programmer, and only have a rudimentary understanding of scripting.
_____
REM - Daily Copy Procedure
@Echo Off
robocopy.exe "C:\TEMP\Source" "C:\TEMP\Destination" *.* /r:1 /w:1 /nfl /ndl /mt /tee /np /log:"robocopy_1.log"
Blat.exe robocopy_1.log -to emyemailaddress -serverSMTP mysmtpserver
_____
I'd like to add something between the Robocopy line and the Blat line that will read the logfile and IF it detects a value greater than zero in the FAILED column, THEN proceed to Blat the logfile to my email address, otherwise exit the batch without running Blat.
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
(EDIT)
Okay, I solved my problem with a simple solution. I was approaching it in probably the most complicated way possible. Robocopy provides detailed error descriptions in its logfiles whenever something goes awry. All I had to do was get the bat file to parse the logfile for the word "ERROR" and all is good. This solution casts a broad net, I'm not looking for any sort of finesse here, so an IF ELSE command did the trick.
REM @ECHO OFF
REM Run Robocopy with appropriate arguments.
robocopy.exe "C:\TEMP\Source" "C:\TEMP\Destination" *.* /r:1 /w:1 /nfl /ndl /s /mt /tee /np /log:"robocopy_1.log"
REM Search for errors in the robocopy logfile and email if any are found.
FIND /c "ERROR" C:\TEMP\robocopy_1.log
IF %errorlevel% equ 1 (EXIT) ELSE (goto mailfile)
REM Email the logfile if problems are found otherwise the BAT will exit before this step.
:mailfile
Blat.exe robocopy_1.log -to myemail -serverSMTP mysmtp