Reputation: 37
I am currently playing around with the FileSystemWatcher class wanted to know how to specify the directory path, but also all of its children files are folders. So it will look for any changes anywhere in C:\ e.g. C:\Program Files\test etc.
string DirPath = "C:\\*.*";
I tried adding . to the directroy path, but no luck
Source code below:
static void Main(string[] args)
{
string DirPath = "C:\\*.*";
FileSystemWatcher FileWatcher = new FileSystemWatcher(DirPath);
FileWatcher.Changed += new FileSystemEventHandler(FileWatcher_Changed);
FileWatcher.Created += new FileSystemEventHandler(FileWatcher_Created);
FileWatcher.Deleted += new FileSystemEventHandler(FileWatcher_Deleted);
FileWatcher.Renamed += new RenamedEventHandler(FileWatcher_Renamed);
FileWatcher.EnableRaisingEvents = true;
Console.ReadKey();
}
Upvotes: 2
Views: 218
Reputation: 74702
Putting a file change notification on all of C: is a terrible idea - if you really want to monitor an entire volume, you should probably use the USN Journal
Upvotes: 1
Reputation: 1431
Use the IncludeSubdirectories property of the FileSystemWatcher.
If you add the line
FileWatcher.IncludeSubdirectories = true;
it will watch all subdirectories in the specified path.
Upvotes: 7