FileSystemWatcher Class - Simple question
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;
Cons开发者_如何学JAVAole.ReadKey();
}
Use the IncludeSubdirectories property of the FileSystemWatcher.
If you add the line
FileWatcher.IncludeSubdirectories = true;
it will watch all subdirectories in the specified path.
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
精彩评论