jpshaver

jpshaver

  • NA
  • 8
  • 0

Simple little problem, but need help

Jan 14 2006 10:11 PM
I'm attempting to use FileSystemWatcher in order to detect when a new bacup (.bak) file is created in a particular directory.  I've set up a little console application that watches for 10 seconds which gives me enough time to create a .bak file.  FileSystemWatcher does not seem to see the new file.  Basically, nothing happens.

In anyone can advise me of my mistake, I'd very much appreciate it! The little bit of code needed is shown below:

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

namespace DataMover

{

class Program

{

static int Main(string[] args)

{

Console.WriteLine("DataMover 1.2 reporting for service.");

FileSystemWatcher fsw = new FileSystemWatcher();

fsw.Filter = "*.bak";

fsw.Path = @"C:\temp";

fsw.IncludeSubdirectories = false;

fsw.EnableRaisingEvents = true;

fsw.WaitForChanged(WatcherChangeTypes.Created, 10000);

fsw.Created+= new FileSystemEventHandler(bak_Created);

return 0;

}

static void bak_Created(object sender, FileSystemEventArgs e)

{

Console.WriteLine("{0} at {1} created!", e.Name.ToString(), e.FullPath.ToString());

Console.ReadLine();

}

}

}



Thanks!

Answers (1)