File System watcher
In this chapter you will learn:
Monitor file system
using System;/*from java2 s . c o m*/
using System.IO;
public class Main
{
// 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();
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » File, Path