Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1916
  • Last Modified:

General Purpose Watch Utility Needed for Windows

I have a folder that has a file show up in it at regular intervals.  When a file is detected, I need to execute a BAT file.  I need a utility that will do this and give me some screens to administer it with.

Thank you - any assistance appreciated.
0
markdolar
Asked:
markdolar
  • 3
  • 2
2 Solutions
 
informaniacCommented:
http://www.pitrinec.com/winscheduler.htm

I think this could help a bit...

By the way, why does the file show up at regular interval. Is it some kind of virus or is it because of some application that you are running
0
 
qz8dswCommented:
File that appears in a certain direcotry?
Add a

if not exist filename exit 1

To the start of your batch file (Obvoiusly change filename in that to the full path and filename of the incoming file)

Then schedule it via windows scheduler would seem to be simplest.
Windows scheduler will return a 0x1 as the result if it tried to run the batch file and the file did not exist.

Terry
0
 
markdolarAuthor Commented:
No, my file is not a virus...I hope.   It is a data file that is created by an application that runs on a schedule.  Though the timing is regular, I don't want to base the job completely on time of day, because of the small chance that job will not run on time.  The combination of the file flag and the windows scheduler would sort of work, but I probably should disclose a few, ahem, requirements:

1. The files will have the same extension (file type), but different names when they show up.
2. Old files might not leave before new ones show up, so the ultiity needs to keep track.
3. Ideally, I would like to run multple versions of the ulility against the file, preferably opening it for read-only shared access.  
4. I would like to use the filename as a data variable in the bat file, distinct from the file type.   The programs I'm running from the bat file will want to create output files with the same filename, but different extensions (file types).  These output files will be placed in a different folder than the watch folder in most cases, but in some cases might be returned to the watch folder for further processing.
5. The feature of a delay in the watch capability ie. don't start processing for x seconds after the file arrives, is potentially useful for load balancing the multiple processes.

WinScheduler looks very good, esp. the advanced edition.  I am also taking a look at FileWatcher 2.2.1.

Thanks for your help...will post again shortly
4.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
markdolarAuthor Commented:
Hello,
I'm ready to close this ticket.  I've been using Filewatcher2.2.1 and I've taken a good long look at winscheduler.  Although I think Winscheduler is a much more powerful tool, I'm using Filewatcher for this job, because it is easier to understand and setup.  It's not perfect, but will work for now and we'll explore winshedule for the future.

I'd like to award points, but have a question along the thread started by qz8dsw - is it possible to resubmit the job to the scheduler within the bat file so that the if the file is not found, the job resubmits to run a little later, say a minute.   Will watch for a response - thanks
Mark

0
 
qz8dswCommented:
Hi Mark,
Thanks for the assist.

It is possible indeed.
You could schedule it to run by windows scheduler every 3 hours as an example but get the batch file on file not found to schedule itself 5 minutes from the current time independant from the 3 hourly one.

Terry
0
 
qz8dswCommented:
something like this works on my XP machine fine.
NOTES
My batch file is called D:\Terry\blah.bat and checks for D:\Terry\fred.txt but can be told to look in a directory and just get the filenames in there or filenames with a certain extension and work with those.

rem -----------begin copy here
@echo off
rem *** This uses a nice wee utility called timemath available at the address below to save on
rem *** date time calculations which would make this batch file huge
rem *** http://gearbox.maem.umr.edu/batch/f_w_util/timemath.zip
rem *** change directory to where timemath.exe is
D:
cd d:\Terry

rem *** check if the file exists
if not exist D:\Terry\fred.txt goto error
rem *** if it doesn't exist it goes to the label :error skipping all lines until it sees :error
rem *** file exists put what you want below here before the :end


:end
rem exit with a 0 meaning no error so task scheduler see's it was successful.
exit 0

:error

rem *** use the util timemath to sort out the time + 1 minutes
for /f "tokens=1 delims=." %%a in ('timemath minute+1 "timeonly"') do set newtime=%%a

rem get the day of the week to cater for if it's 23:59 and about to roll over a day
for /f "tokens=3 delims=" %%a in ('timemath minute+1') do set newday=%%a

rem *** Schedule a new scheduled event
at %newtime% /next:%newday% "D:\Terry\blah.bat"

rem *** exit with an error so task scheduler picks up the error for the main scheduled event
exit 1
rem -----------End copy here

Terry
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now