我有这段代码来检测删除文件。
m_Watcher = new System.IO.FileSystemWatcher();
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnCreated);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnDeleted);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
private void OnDeleted(object sender, FileSystemEventArgs e)
{
Debug.WriteLine(e.FullPath);
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
Debug.WriteLine(e.FullPath);
}
但是当我使用Shift删除多个文件时,它只检测到1个文件。
我知道应该通过WaitForChanged
方法纠正它,但我不知道如何实现它。
经典代码无效https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.deleted(v=vs.110).aspx
感谢您的帮助!
答案 0 :(得分:0)
我在这里找到了工作解决方案
FileSystemWatcher - Pure Chaos(第1部分,共2部分)
http://www.codeproject.com/Articles/58740/FileSystemWatcher-Pure-Chaos-Part-of