2

Is it possible to configure a FileSystemWatcher to watch other folders which are linked in with a folder junction point?

for example:

You are watching D:

You have D:\junction which points to E:\folder

When I create a file in E:\folder\file.txt I want to see it with the watcher as D:\junction\file.txt.

Is this possible?

Thanks.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
fpdragon
  • 1,867
  • 4
  • 25
  • 36

3 Answers3

5

FileSystemWatcher is not supposed to monitor junctions or symlinks... and it monitors one folder at a time.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
m0s
  • 4,250
  • 9
  • 41
  • 64
  • "monitors one folder at a time"... yes, but you can configure to also watch subfolders. junctions in subfolders seems to be not resolved by filesystemwatcher... :-( – fpdragon Feb 09 '11 at 11:49
2

Although Junctions are not supported, I believe Hard Links are:

GateKiller
  • 74,180
  • 73
  • 171
  • 204
  • 1
    Yes Hardlinks must be supported since every normal file is nothing else than a hard link. The other thing is that hardlinks are for files and junctions for folders. I have links between folders so I use junctions. thx anyway – fpdragon Feb 09 '11 at 12:30
1

A workaround is to setup FileSystemWatcher for each subfolder including junction points.

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);
    }
  }
Raman Zhylich
  • 3,537
  • 25
  • 23