用FileSystemWatcher监视文件变化

 


c#中一个非常方便的工具。以前用vc++6.0实现监视文件变化,要么需要函数钩子,要么需要写驱动程序。
System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher(path, baseName);
FileSystemEventHandler handler = new FileSystemEventHandler(FileOnChanged);
watcher.Changed += handler;
watcher.Created += handler;
watcher.Deleted += handler;
watcher.Renamed += OnRenamed;
// Without setting EnableRaisingEvents nothing happens
watcher.EnableRaisingEvents = true;

protected void FileOnChanged(object sender, FileSystemEventArgs e)
{

string name = e.Name.ToLower();
string fullPath = e.FullPath;
}
需要注意在调用fileonChanged的时候,不要一直调用FileOnChanged

你可能感兴趣的:(C++,c,C#,vc++)