是否可以配置 aFileSystemWatcher
以查看与文件夹连接点链接的其他文件夹?
例如:
你在看 D:
你有 D:\junction 指向 E:\folder
当我在 E:\folder\file.txt 中创建一个文件时,我想用观察者将它作为 D:\junction\file.txt 来查看。
这可能吗?
谢谢。
是否可以配置 aFileSystemWatcher
以查看与文件夹连接点链接的其他文件夹?
例如:
你在看 D:
你有 D:\junction 指向 E:\folder
当我在 E:\folder\file.txt 中创建一个文件时,我想用观察者将它作为 D:\junction\file.txt 来查看。
这可能吗?
谢谢。
FileSystemWatcher
不应该监控连接点或符号链接......它一次监控一个文件夹。
虽然不支持结点,但我相信硬链接是:
一种解决方法是为每个子文件夹(包括连接点)设置 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);
}
}