Windows batch script help needed

A simple one for the experts community I am sure. I currently have a batch file which executes an action on a file based on it size.

FOR /R "C:\Pictures\" %%F IN (*.jpg) DO IF %%~zF GTR 2000000 Action2.exe <options> %%~sF

I am looking for a way to replace the file size check with a sub-string search of the output of another executable (Action1.exe). If the sub-string is NOT present, then execute Action2.exe

Walk directory structure
Execute Action1.exe on all .jpg files
If the output of Action1.exe does not contain the text "Sample" then execute Action2.exe on .jpg file.
Both Action1.exe and Action2.exe have options which must be passed to them.

Thank you.
Who is Participating?
oBdAConnect With a Mentor Commented:
Try this; the script is currently in test mode and will only display Action2.exe; remove the uppercase ECHO in line 12 to run it for real:
@echo off
setlocal enabledelayedexpansion
set SourceRoot=C:\Pictures
set FileMask=*.jpg
set SearchString=Sample
set Action1Options=-action 1
set Action2Options=-action 2
for /r "%SourceRoot%" %%a in (%FileMask%) do (
	echo "%%~fa"
	Action1.exe %Action1Options% "%%~fa" | find /i "%SearchString%" >NUL
	if errorlevel 1 (
		ECHO Action2.exe %Action2Options% "%%~fa"

Open in new window

CashmanPhotoAuthor Commented:
Perfect. Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.