Windows File system monitoring service
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
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);
}
}
}
My end goal is to automatically take a copy of the file for backup when one of these events occur.
Re: Windows File system monitoring service
Can you track when the file is created and every time it is changed? Then when it's deleted, you would already have saved the most recent info on it, and could restore from there. Of course this complicates your application because you would need a data store which could grow large depending on filesystem activity, but I don't know of another alternative.