c#可以利用FileSystemWatcher監控檔案or資料夾的新增、更名、修改、刪除的動作
例:
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.IncludeSubdirectories = true;
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Path = "c:\\";
watcher.Filter = "*.*";//監控所有文件," *.txt " -->只監控.txt檔
watcher.NotifyFilter = NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.Size;
//begin watching.
watcher.EnableRaisingEvents = true;
參考網站
- Jul 31 Fri 2009 11:47
[C#]FileSystemWatcher監控檔案or資料夾
close
全站熱搜
留言列表