Using filesystemwatcher

I desperately needed to find out where Adobe Photoshop Album 2.0 stores its database files (damn software that doesn't allow configuring this!). Well, a quick search of the obvious places didn't reveal a thing, so I wrote a few lines of code to monitor the files being accessed. The following code is a trivial console program to monitor what's going on in your C: drive. Don't you just love the ease of .NET?

using System;
using System.IO;
namespace fswatchtest
{
class Program
{
static void Main(string[] args)
{
FileSystemWatcher fswC = new FileSystemWatcher(@"c:\");
fswC.IncludeSubdirectories = true;
fswC.Changed += new FileSystemEventHandler(fsw_Changed);
fswC.EnableRaisingEvents = true;
Console.ReadLine();
}
static void fsw_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.FullPath);
}
}
}

January 8, 2005 В· Jouni Heikniemi В· 2 Comments
Posted in: .NET

2 Responses

  1. Xanthros - January 11, 2006

    Actually the ease of which it creates bugs or the number of workarounds needed is even more amazing. Try creating a FileSystemWatcher that uses a filter to look at a specific file. Then watch for changes. You don't get one event for any change to your file. You get multiple. That's great! Open up the file and write to it once and you get two events. Use Textpad to change the file and you get four events.
    Very lame!

  2. Ant - March 29, 2006

    Agree with Xanthros, when you drop a big file in teh folder , the created event fires when the file is zero bytes and again when it is finished copying, and you can;t tell which is which