I want to monitor my file system. I'm fine with file changed events but the File Deleted has already deleted the file by the time I come to do my operation on it.
How do I track file changes/information for files which are Overwritten (Copy Paste) or deleted?
Im using this code from http://www.codeproject.com/Articles/...ing-System-Dir
My end goal is to automatically take a copy of the file for backup when one of these events occur.Code:using System; using System.IO; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { FileSystemWatcher Watcher = new FileSystemWatcher(); Watcher.Path = Environment.SystemDirectory; Watcher.IncludeSubdirectories = true; Watcher.Created += new FileSystemEventHandler(Wathcer_Changed); Watcher.Deleted += new FileSystemEventHandler(Wathcer_Changed); Watcher.EnableRaisingEvents = true; Console.ReadLine(); } static void Wathcer_Changed(object sender, FileSystemEventArgs e) { Console.WriteLine("Change Type = {0}, Path = {1}", e.ChangeType, e.FullPath); } } }





Reply With Quote