本文介绍了如何监视 Windows 目录的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
解决方案
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 on arrival of new files.
// 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.EnableRaisingEvents = true;
watcher.Created += new FileSystemEventHandler(WatcherCreated);
void WatcherCreated(object source , FileSystemEventArgs e)
{
//Code goes here for when a new file is detected
}
这篇关于如何监视 Windows 目录的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!