How to monitor a folder for changes, and execute a command if it does, on Windows?

There are similar questions for Linux and Mac, but I'm after a Windows solution here.

The problem is as follows: I want to write several (js) script files in a folder, and have a program monitor that folder for file changes and new files being added, and run a command whenever that happens (to compile them all into one single file).

The solution has to:

  1. Monitor both file changes and new files being added, in a folder.
  2. Run a command only if there is any change.

It would be best if it either is a built-in solution (like a JScript or VBscript snippet), or something that does not require installation.


Solution 1:

There's a program called Belvedere that might do the trick.

http://ca.lifehacker.com/341950/belvedere-automates-your-self+cleaning-pc

It's a stand alone Windows app that runs in the background.

I've set it up to monitor my downloads folder for files with certain extensions with last modified dates of a day old. The files it finds, it deletes, however you could have it run an action instead.

Solution 2:

I've had good success with an old program called Log Monitor. It's ancient, and long ago abandoned. But it serves the purpose pretty well.

http://www.freeware-guide.com/download/index2.html

Solution 3:

I have created a simple utility for this purpose: https://github.com/benblamey/when_changed

usage: when_changed (file path) (command) (optional-parameters)

e.g. when_changed C:\somedir\foo.txt myapp.exe bar wibble 123