public FileSystemWatcher fsw;
public void StartMonitoring()
{
//Get all Drives of Computer
DriveInfo[] dinfo = DriveInfo.GetDrives();
//Loop Through All The Drives
foreach (DriveInfo d in dinfo)
{
try
{
fsw = new FileSystemWatcher(d.RootDirectory.ToString());
fsw.EnableRaisingEvents = true;
fsw.IncludeSubdirectories = true;
fsw.Renamed += new RenamedEventHandler(FileRenamed);
fsw.Created += new FileSystemEventHandler(FileCreated);
fsw.Deleted += new FileSystemEventHandler(FileDeleted);
}
catch
{
}
}
}
public void FileRenamed(Object Sender, RenamedEventArgs e)
{
messagebox.show( e.FullPath, "Renamed");
}
public void FileCreated(Object Sender, FileSystemEventArgs e)
{
messagebox.show( e.FullPath, "Created");
}
public void FileDeleted(Object Sender, FileSystemEventArgs e)
{
messagebox.show( e.FullPath, "Deleted");
}
public void StopMonitoring()
{
fsw.Dispose();
}