Mega Code Archive

 
Categories / C# / File Stream
 

Illustrates the FileSystemWatcher class

/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */  /*   Example15_9.cs illustrates the FileSystemWatcher class */ using System; using System.IO; public class Example15_9  {   // event handler for file change   public static void OnChanged(object source, FileSystemEventArgs e)    {     // dump info to the screen     Console.WriteLine("Change to " + e.FullPath + ": " +      e.ChangeType);   }   public static void Main()    {     // create a watcher for the c: drive     FileSystemWatcher fsw = new FileSystemWatcher("c:\\");     fsw.IncludeSubdirectories = true;     // hook up the event handler     fsw.Changed += new FileSystemEventHandler(OnChanged);     // turn on file watching     fsw.EnableRaisingEvents = true;          // And wait for the user to quit     Console.WriteLine("Press any key to exit");     int i = Console.Read();   } }