FileSystemWatcher和隐藏共享

时间:2015-12-28 15:23:43

标签: c# filesystemwatcher

我有一个隐藏的份额:

  \\computername\Logs$

我需要监控该共享中的文件更改。 我决定使用FileSystemWatcher Class,但它不会引发任何事件。它并没有向我显示任何错误。

static void Main(string[] args)
{
  FileWatcher fw = new FileWatcher(@"\\computername\Logs$", "*.*");
  fw.Start();
}

class FileWatcher(string filePath, string mask)
{
  FileSystemWatcher watcher;
  watcher.Path = filePath;
  watcher.Filter = mask;
  watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
  watcher.Changed += Watcher_Changed;
  watcher.Error += OnError;

  public void Start()
  {
    watcher.InternalBufferSize = 64 * 1024;
    watcher.EnableRaisingEvents = true;
    Console.WriteLine("Watcher Started");

    while (!Console.KeyAvailable)
    {
      Thread.Sleep(1000);
    }
  }

  private void Watcher_Changed(object sender, FileSystemEventArgs e)
  {
    Console.WriteLine("File Changed");
  }

  private void OnError(object sender, ErrorEventArgs e)
  {
    Console.WriteLine("Error");
  }
}

FileSystemWatcher是否可以正常使用隐藏共享?

1 个答案:

答案 0 :(得分:0)

此代码无法编译,也许您在复制代码时遇到错误 并且事件处理程序Watcher_Changed,也许你有错误并把Watcher_Created改为