Results 1 to 2 of 2

Thread: Windows File system monitoring service

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    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.

  2. #2
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,566

    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.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width