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();
}
Use the IncludeSubdirectories property of the FileSystemWatcher.
If you add the line
it will watch all subdirectories in the specified path.