views:

1352

answers:

4

When a change is made within a directory on a Windows system, I need a program to be notified immediately of the change.

Is there some way of executing a program when a change occurs?

I'm not a C/C++/.NET programmer, so if I could set up something so that the change could trigger a batch file then that would be ideal.

+3  A: 

Use a FileSystemWatcher

SQLMenace
Will I need Visual Studio? Can I use this from VBScript?
Liam
FileSystemWatcher is .Net so yes this solution would require Visual Studio.
Refracted Paladin
+1  A: 

If you want something non-programmatic try GiPo@FileUtilities ... but in that case the question wouldn't belong here!

Rob Walker
+4  A: 

Use a FileSystemWatcher like below to create a WatcherCreated Event(). I used this to create a Windows Service that watches a Network folder and then emails a specified group ofa anew files arrival.

// Declare a new FILESYSTEMWATCHER
    protected FileSystemWatcher watcher;


 string pathToFolder = @"YourDesired Path Here";


 // Initialize the New FILESYSTEMWATCHER
        Watcher = new FileSystemWatcher {Path = PathToFolder, IncludeSubdirectories = true, Filter = "*.*"};
        Watcher.Created += new FileSystemEventHandler(WatcherCreated);     

        void WatcherCreated(object source , FileSystemEventArgs e)
{Code goes here for when a new file is detected}
Refracted Paladin
I know you post states you are not a .NET programmer but with a copy of Free Visual Studio Express and the code I posted you are %80 af the way there. Stack OverFlow can probably get you the other %20. Depending on what you want to do with the detected file this is a very simple solution to implement and deploy. If you are interested I can elaborate my post to the who Window Service Creation.
Refracted Paladin
Thanks, I haven't used C# in a few years but if it is the best tool for the job then it is worth the extra effort. I'll set up Visual C# Express Edition. Thank you.
Liam
+1  A: 

There is no utility or program the comes with Windows to do it. Some programming required.

As noted in another answer, .NET's FileSystemWatcher is the easiest approach.

The native API ReadDirectoryChangesW is rather harder to use (requires an understanding of completion ports).

Richard