2016-01-11 112 views
0

我有此代碼來檢測刪除文件。FileSystemWatcher未檢測到多文件刪除

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

你設置的屬性'watcher.Path =「<目錄路徑> 「'和'watcher.Filters =」<所有文件類型都爲空>「'?儘管這太天真了,不能問。但是這裏的代碼片段並不顯示它。 – vendettamit

+1

似乎與以下四年的解決方案類似:http://stackoverflow.com/a/8442063/1845672 – Roland

+0

@vendettamit是的。 –

回答