Это помечено для Winapi, но я все равно делаю это с .net.
Для этого вы можете использовать класс FileSystemWatcher из System.IO.
static void Main(string[] args)
{
FileSystemWatcher fsw = new FileSystemWatcher("C:\\");
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);
fsw.EnableRaisingEvents = true;
fsw.IncludeSubdirectories = true;
fsw.Renamed += new RenamedEventHandler(fsw_Renamed);
Console.Read();
}
static void fsw_Renamed(object sender, RenamedEventArgs e)
{
Console.WriteLine("{0} was changed to {1}", e.OldName, e.Name);
}
static void fsw_Deleted(object sender, FileSystemEventArgs e)
{
Console.WriteLine("{0} was deleted", e.Name);
}
static void fsw_Created(object sender, FileSystemEventArgs e)
{
Console.WriteLine("{0} was created", e.Name);
}
static void fsw_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine("{0} was changed", e.Name);
}