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.

1
  • 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 answer maybe Commented Dec 7, 2015 at 18:44

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks You! Could you please elaborate on how I would use a utility like sendmail.exe or alike in this syntax?
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 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 page on that as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.