2

是否可以配置 aFileSystemWatcher以查看与文件夹连接点链接的其他文件夹?

例如:

你在看 D:

你有 D:\junction 指向 E:\folder

当我在 E:\folder\file.txt 中创建一个文件时,我想用观察者将它作为 D:\junction\file.txt 来查看。

这可能吗?

谢谢。

4

3 回答 3

5

FileSystemWatcher不应该监控连接点或符号链接......它一次监控一个文件夹。

于 2011-02-09T11:28:04.920 回答
1

一种解决方法是为每个子文件夹(包括连接点)设置 FileSystemWatcher。

private static void SetupFileSystemWatchers(string path, FileSystemEventHandler changedEventHandler)
{
  if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
  {
    var watcher = new FileSystemWatcher(path);
    watcher.IncludeSubdirectories = false;
    watcher.Changed += changedEventHandler;
    watcher.EnableRaisingEvents = true;

    foreach (var subDirectory in Directory.GetDirectories(path))
    {
      SetupFileSystemWatchers(subDirectory, changedEventHandler);
    }
  }
于 2016-09-09T21:10:58.727 回答