-1

I am looking for a way to run a batch file and find a file within subdirectories. If the file is found just exit but if its not found go ahead and run command. This is what I have so far but it doesnt look through subdirectories.

timeout /t 30
IF EXIST Z:\K\Downloads\*.tmp (
echo Nope
exit
) ELSE (
psexec \\192.168.2.120 -h -u Filebot -p password -i -s "K:/Downloads/Filebot/FilebotMedia.bat"
)
ml3000
  • 3
  • 2
  • Try dir z:\file /S /b and check the output – Marged Jan 08 '16 at 20:16
  • I tried that and it doesnt execute the ) ELSE ( – ml3000 Jan 08 '16 at 20:20
  • Show what _exactly_ you tried – Marged Jan 08 '16 at 20:22
  • timeout /t 30 IF EXIST dir Z:\K\Downloads\*.tmp /S /b ( echo Nope exit ) ELSE ( psexec \\192.168.2.120 -h -u Filebot -p password -i -s "K:/Downloads/Filebot/FilebotMedia.bat" ) – ml3000 Jan 08 '16 at 20:25
  • This is syntactically incorrect. Use Dir alone and.combine this with findstr or find. Or change your current code along this:http://ss64.com/nt/for_r.html – Marged Jan 08 '16 at 20:27
  • If I use dir "Z:\K\Downloads\*.tmp" by itself I am able to find the files. But then how am I able to execute another command if they are found or if they are not, else, do something else? Sorry I am a bit confused. – ml3000 Jan 08 '16 at 20:30

1 Answers1

1

Try this:

@echo off
timeout /t 30
>nul 2>nul dir /a-d /s "Z:\K\Downloads\*.tmp" && (
  echo Nope
  exit
) || (
  psexec \\192.168.2.120 -h -u Filebot -p password -i -s "K:/Downloads/Filebot/FilebotMedia.bat"
)
pause

The basis of this is found in this answer, but edited so it only works for your specific extension.

Please note that users won't be able to see what you echo as you have no pause after your echo.

Community
  • 1
  • 1
Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35