0

I would like to run a batch script with the following syntax:

@echo off
for %%b in ("batchscript1.bat" "bat2" "bat3" "bat4" "etc" "etc") do (
    call %%b || exit /b 1
)

How could I implement code into this syntax that looks for a file in a specified directory after each bat is executed.

The reason for this is after each batch file is executed if it fails a log is written to a directory. I would like to see if any files exist so that an email can be sent.

Alvaro Montoro
  • 28,081
  • 7
  • 57
  • 86
Georgep2000
  • 39
  • 2
  • 7
  • Do you know the format of the names of the files created after the batches execution? Is `IF EXIST filename` what you are looking for? Check [this](http://stackoverflow.com/questions/3022176/how-to-verify-if-a-file-exists-in-a-windows-bat-file) answer maybe – Daniel Luz Dec 07 '15 at 18:44

1 Answers1

0

Use IF EXIST filename - http://ss64.com/nt/if.html

@echo off
for %%b in ("batchscript1.bat" "bat2" "bat3" "bat4" "etc" "etc") do call :runBatch %%b
GOTO:EOF

:runBatch
:: %1 - parameter called from the for loop (batchscript1.bat, bat2.bat, etc...)
call %1
if exist "batch.log" (
:: log exists, send email
)
GOTO:EOF

IF EXIST filename can also take a wildcard pattern if each batch file creates log with a different name

Tommy Harris
  • 109
  • 6
  • Thanks You! Could you please elaborate on how I would use a utility like sendmail.exe or alike in this syntax? – Georgep2000 Dec 08 '15 at 18:50
  • Oh goodness, that's a whole different animal. What kind of resources do you have available in the environment? I've never played with it too much myself, but I worked with a client once who did [something like this](http://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/) with PowerShell; you would call the powershell script after your if statement there, and maybe even pass some info from the batch to it. Check out [ss64's](http://ss64.com/ps/send-mailmessage.html) page on that as well. – Tommy Harris Dec 09 '15 at 01:34