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:
- Monitor both file changes and new files being added, in a folder.
- 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.
111 Answers
There's a program called Belvedere that might do the trick.
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.
3I'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.
2I have created a simple utility for this purpose:
usage: when_changed (file path) (command) (optional-parameters)
e.g. when_changed C:\somedir\foo.txt myapp.exe bar wibble 123
2With .NET watchfolders this is really easy to code. I'm sure someone have done such a program.
Just found this gem for you
1I'm currently trying this app, which requires .NET, but looks like it does the job.
Yet another tool:
Advantages: Platform independent (Java), small (10KB).
Disclaimer: I am the author
This is such a common requirement that I'm surprised there's no convenient utility built into the OS itself.
Anyway as mentioned earlier I've used LogMonitor successfully in the past. However I found this blog post informative and am using Watch 4 Folder now.
Hopefully this helps you out.
2If you want to do a built-in solution using JScript or VBScript, then what you want to look for is file system monitoring using WMI event subscriptions. Basically you write the code to monitor a folder and preform actions when a change is detected such as:
__InstanceCreationEvent__InstanceDeletionEvent__InstanceModificationEvent
...and your script runs on an interval watching for these events to occur. There are many resources, but here are some for VBScript and Powershell:
0NirSoft has software for monitor files changes on Windows
FolderChangesView
FolderChangesView is a simple tool that monitors the folder or disk drive that you choose and lists every filename that is being modified, created, or deleted while the folder is being monitored. You can use FolderChangesView with any local disk drive or with a remote network share, as long as you have read permission to the selected folder.
you can download it for free from here
More Info
You can use which subscribes to os-specific filesystem monitoring events. The code is years old but still works (at least on the Windows Server 2013r2 I was testing it yesterday).
There is also github resurrection of jnotify project on which does not offer standalone demo app but (according to commit logs) patches some bugs.
In java7 there should be some kind of inotify-like filesystem watch too, but I was not testing it yet.
If you are fine with polling for changes then is another option. It's a Go package but it also provides a command line interface.
- Install Go (e.g.
choco install golangor follow ). - Ensure
gois in your PATH by runninggo version. The installation from step 1 should add%UserProfile%/go/binto PATH. - Run
go get -uas instructed in the readme. - Run
watcher -cmd="your_command"inside the desired directory (e.g.watcher -cmd="npm run build" javascript/*).
This should also work non-Windows platforms, it's simple polling after all.
This shouldn't require Go to run because all binaries from %UserProfile%/go/bin are statically linked. So you can then move the couple of executables somewhere else and remove Go.