0
Answer

Problem about FileSystemWatcher..

ivesorange

ivesorange

20y
1.3k
1
Hi.. I want to know about file creation,modification and deletion on the disk. I got the code below from MSDN. ======================================================= FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "d:\\"; watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName; watcher.Filter = "*.*"; watcher.IncludeSubdirectories = true; watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnChanged); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.EnableRaisingEvents = true; private static void OnChanged(object source, FileSystemEventArgs e) { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } ======================================================= But when I run this program, I created a new file and saved it. I got the message below: File: d:\new text document.txt Created File: d:\new text document.txt Changed File: d:\new text document.txt Changed I just saved one time,but it got twice event. How can I fix this problem. And it sometimes gets directories changed message, Why??
Next Recommended Forum