Question Batch file / script to execute command when file with a pattern appear ?

DynV

Distinguished
Aug 13, 2009
234
3
18,685
0
There's a program that will sometimes run for a long time that I don't want to stop in the middle of a file. When that happen I'll look at the program in between my tasks, that I estimate the vast majority of the time are between 2 & 10 mins. The program shows the file name it will output when the task is complete.

I'd like a batch file or script to "keep an eye" in the output directory for a file with a pattern that matches what's displayed on the program appear, and when it does execute a command to close the program (taskkill /f /im NAME.exe). It doesn't have to constantly look, every 1-3 mins is fine.

Thank you kindly for your help

Update 1
I'd also like a timeout in case the file-creating program crashes or I entered the file pattern incorrectly, ie 6 hrs.
 
Last edited:

kanewolf

Titan
Moderator
There's a program that will sometimes run for a long time that I don't want to stop in the middle of a file. When that happen I'll look at the program in between my tasks, that I estimate the vast majority of the time are between 2 & 10 mins. The program shows the file name it will output when the task is complete.

I'd like a batch file or script to "keep an eye" in the output directory for a file with a pattern that matches what's displayed on the program appear, and when it does execute a command to close the program (taskkill /f /im NAME.exe). It doesn't have to constantly look, every 1-3 mins is fine.

Thank you kindly for your help
Powershell is easy to write. There are lots of resources. The command to wait an amount of time is "Start-Sleep" It will put the script to sleep for a specified number of seconds.
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-7.2
 

ASK THE COMMUNITY