In my tests, the FileSystemWatcher did see sub-directory creation, and
worked as expected. When monitoring "C:\Temp\", this included seeing
the creation/modification of "C:\Temp\New Folder\Test.txt" only when
FileSystemWatcher.IncludeSubDirectories was set to true.
However, I am running on Windows 7, so perhaps it is an OS issue.
Would you mind sending a copy of your sample code, so that I can test
it out in Windows 7 in the spirit of comparing apples to apples?
The code I am using:
(C:\Temp\ must already exist, and your account must have credentials
to modify it, or else an exception will be thrown.)
//============================
using System;
using System.IO;
namespace FileSystemWatcherSample
{
class Program
{
static void Main(string[] args)
{
FileSystemWatcher fsWatch = new FileSystemWatcher(@"C:
\Temp");
fsWatch.Created += FsWatchCreated;
fsWatch.Changed += FsWatchChanged;
fsWatch.Deleted += FsWatchDeleted;
fsWatch.Renamed += FsWatchRenamed;
fsWatch.EnableRaisingEvents = true;
fsWatch.IncludeSubdirectories = true;
Console.ReadLine();
fsWatch.EnableRaisingEvents = false;
}
private static void FsWatchRenamed(object sender,
RenamedEventArgs e)
{
Console.Out.WriteLine("Renamed: " + e.FullPath);
}
private static void FsWatchDeleted(object sender,
FileSystemEventArgs e)
{
Console.Out.WriteLine("Deleted: " + e.FullPath);
}
private static void FsWatchChanged(object sender,
FileSystemEventArgs e)
{
Console.Out.WriteLine("Changed: " + e.FullPath);
}
private static void FsWatchCreated(object sender,
FileSystemEventArgs e)
{
Console.Out.WriteLine("Created: " + e.FullPath);
}
}
}
//==========================================
--
Jay Harris
On May 20, 11:27 pm, "
Spyder2...@comcast.net" <
Spyder2...@comcast.net>
wrote:
> The question was "Does the FileSystemWatcher object see the creation
> of Directories?"
>
> In short my test, found that it did not. However it did find the
> files created in that directory. So a FileSystemWatcher crated to
> watch c:\temp would find c:\temp\test.txt, but not c:\temp\New Folder
> \ It would also find the c:\temp\New Folder\test.txt. So question
> number 2 at the bottom of page77 seems to have the answer B and C
> thus the book on page 711 seems to be wrong.
>
> My test was run on a fully patched version of Vista Ultimate and
> VS2008
>
> I took this a step further and found the following msdn docs on the
> subject.
> "FileSystemWatcher Class", "Listens to the file system change
> notifications and raises events when a directory, or file in a
> directory, changes."
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
>
> "FileSystemWatcher Members", "Created" "Occurs when a file or
> directory in the specified Path is created."
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher_m...