使用FileSystemWatcher并设置watcher.IncludeSubdirectories = true
时。
我只能捕获到两个级别向下的子目录的更改(例如Dir/SubDir1/SubDir2
)。但是,如果我想要该目录以外的内容(例如Dir/SubDir1/SubDir2/.../...
),则不会引发任何事件。
我使InternalBufferSize = 65536
超出极限。有没有办法进入更深的嵌套子文件夹?
这将在网络驱动器文件夹上运行和测试:
using (FileSystemWatcher _watcher = new FileSystemWatcher())
{
_watcher.Path = directory;
_watcher.IncludeSubdirectories = true;
_watcher.NotifyFilter = NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
_watcher.Changed += new FileSystemEventHandler(Program._watcher_Changed);
_watcher.Created += new FileSystemEventHandler(Program._watcher_Changed);
_watcher.Deleted += new FileSystemEventHandler(Program._watcher_Changed);
_watcher.Renamed += new RenamedEventHandler(Program._watcher_Renamed);
_watcher.Filter = "*.*";
_watcher.InternalBufferSize = 65536;
_watcher.EnableRaisingEvents = true;
Console.WriteLine("Press 'q' to quit the sample.");
while (Console.Read() != 'q');
}