General Purpose Watch Utility Needed for Windows

Posted on 2007-08-10
Last Modified: 2013-11-05
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.
Question by:markdolar
    LVL 20

    Accepted Solution


    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
    LVL 15

    Assisted Solution

    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.


    Author Comment

    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

    Author Comment

    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

    LVL 15

    Expert Comment

    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.

    LVL 15

    Expert Comment

    something like this works on my XP machine fine.
    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 ***
    rem *** change directory to where timemath.exe is
    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

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


    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
    Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now