Tip

Freeware tool logs file system events

Please let us know how useful you find this tip by rating it below. Do you have a useful Windows tip, timesaver or workaround to share? Submit it to our tip contest and you could win a prize!


I have often

Requires Free Membership to View

been asked if it's possible for Windows to "watch" a given file and perform an action if the file is modified. There hasn't been a built-in provision in Windows to do this, except in the sense that you could write a kernel-level file system filter to trap such actions.

Well, the wait is finally over. XTWare has created a free service called FileNotify that traps events on specific directories and performs an action when anything is changed or modified.

FileNotify is a lightweight program: It's a single executable that runs as a system service. There is, however, no installer -- it needs to be registered by hand, but it is easy enough to remove as well. Once set up, you can create a list of directories (with a supplied editor application) that watches for any of the following actions: file creation or modification, deleting files, modifying attributes or names (including long filenames) and changing security tokens. You can use any of these actions to trigger a command-line action, such as a batch file or an .EXE.

The program logs its actions to a text file that, by default, is FileNotify.Log (located in the directory that FileNotify itself is running in).

The program also checks directories recursively -- you can point it at a top-level directory and ask it to watch all files or folders under that directory.

Be warned that if one of the actions triggered by a file change involves modifying a file in one of those watched directories, it can create a race condition. Also, whenever a file is changed, FileNotify waits for a full second of inactivity on that file before attempting to perform any actions on its own. It does this because sometimes when a file is changed, the Last Modified attribute is updated multiple times. The delay allows all of the changes to "settle" before action is taken.

Finally, FileNotify cannot monitor activity on a single file, but you can work around this by using a batch file with an input parameter (i.e., mybatchfile.bat %1) as the on-change action. The first line of the batch file can filter for a specific file like this:

If "%1"=="filename.fil" goto myaction


Serdar Yegulalp is editor of the Windows Power Users Newsletter. Check it out for the latest advice and musings on the world of Windows network administrators -- and please share your thoughts as well!


This was first published in July 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.