FNotify is a batch file utility designed to allow construction of
an efficient batch file for processing files which are added to a directory.
Normally such a batch would need to periodically check for files it is
designed to process using IF EXIST. This is very inefficient
because the computer is using processor time to check for these
files even when none exist. FNotify uses the Windows File Change
Notification API which uses no processor time while it is waiting for
a change to occur in the directory it is monitoring, but responds
immediately when the change occurs.
Many home printers do not allow sharing the printer on a network. The
batch below allows network users to print to a file that will
automatically be sent to the printer. Note that the -timeout option is
used with FNotify and the batch detects the timeout and runs whatever
is specified. This allows the batch to perform some other task
periodically (in this example, every 5 minutes). The batch is
designed to look for a file with the reserved name $Exit.flg. This is
a signal for the batch to end. Any number of such reserved file names
could be used to signal actions to be performed.
:FNOTIFY
FNotify -timeout:5m .\
IF ERRORLEVEL 2 GOTO END
IF ERRORLEVEL 1 GOTO TimeOut
IF EXIST $Exit.flg GOTO Quit
:FileLoop
IF NOT EXIST *.prn GOTO FNOTIFY
REM Rename the first PRN file to $.prn
REN *.prn $.prn
COPY /B $.prn PRN
DEL $.prn
GOTO FileLoop
:TimeOut
REM Do whatever you want to happen on timeout here
GOTO FNOTIFY
:Quit
DEL $Exit.flg
REM Do whatever you want to happen when exit signal is sent
:END
Here is the program usage:
FNotify - Copyright (C) 2009, Incode Systems, Inc.
Usage: [options] Path
FNotify waits for one of the changes specified to occur in
the Path given. FNotify exits with ERRORLEVEL 0 if change detected.
Path is the directory to monitor. To monitor the working
directory, use .\ as the Path.
FNotify uses File Change Notification to report changes,
so it uses virtually no processor time while waiting and exits
virtually immediately when the change is detected.
Options:
-s Monitor subdirectories
-FileName Monitor file name changes
-DirName Monitor directory name changes
-Attribs Monitor file attribute changes
-Size Monitor file size changes
-LastWrite Monitor LastWrite timestamp changes (default)
-LastWrite- Do NOT Monitor LastWrite timestamp changes
-Security Monitor file security changes
-timeout:n n is the number of milliseconds to timeout
default is 0, which waits forever.
n may end in s for seconds, m for minutes, h for hours.
FNotify exits with ERRORLEVEL 0 if the change indicated by the
options occurs.
ERRORLEVEL 1 if time out.
ERRORLEVEL 2 if User exits with Ctrl-C, Ctrl-Break, or System logout, etc.
ERRORLEVEL 3 if Path not found.
ERRORLEVEL 4 if Wait Failed.
ERRORLEVEL greater than 4 indicates an OS error.
The default 0 timeout causes FNotify to wait forever for the
change specified. In this case, exit the program with Ctrl-C or Ctrl-Break.
To cause the program to exit programmatically, just create a change
in the monitored directory and check for that change in the batch file.
Version 0.9.1
www.incodesystems.com
mailto:sales1@incodesystems.com
To see complete usage, type FNotify /? | more