locked
FileSystemWatcher doesn't watch through NTFS Junction Points? RRS feed

  • Question

  • Hi,

    For part of my current project, I need to be able to watch a set of directories for file creation/deletion/modification etc - not a problem, .NET provides me with FileSystemWatcher to do just that. This works 100% on a set of 'normal' directories such as:

    Users/test
    Users/test2
    Users/test3

    and so on.

    Now alongside this 'normal' structure I have a similar directory structure that will 'map' to somewhere else on the filesystem. For example:

    Users/My Files

    Will actually point to :

    Data/User/000234/aabc/

    The way that I have done this is to use NTFS Junction Points (symbollic links), which I create and delete through the win32 library. This completely abstracts this mapping from the user - so in the explorer address bar they see "Users/My Files" and not "Data/User...etc".

    The problem is that fileSystemWatcher completely ignores these links. It works fine if I modify a file inside a 'real' folder, but if I try and do it through a Junction Point I get nothing.

    Anyone got any ideas? Possibly an undocumented property or something that will force it to treat Junction Points in the same way that explorer does (ie as a real folder)?

    edit: I have worked around this for now by setting up multiple FSWs for each junction point that I create - but as I have 5 junction points it would be much easier (and more efficient) to just have 1 FSW monitoring the top directory..so any ideas/hints are still most welcome Smile
    Friday, April 6, 2007 4:04 PM

Answers

  • I could find no authoritative statement that says that FSW doesn't work through junction points.  I'm not surprised it doesn't, your findings are convincing to me.  As is the workaround you used.
    Friday, April 6, 2007 5:38 PM
  • FileSystemWatcher is implemented with ReadDirectoryChangesW, which is documented with

    To track changes on a volume, see change journals.

    A "volume" is also known as a Volume Mount Point, reparse, or junction point.

     

    Although, not very explicit, it sounds like ReadDirectoryChangesW does not support junction points.

    Saturday, April 7, 2007 9:17 AM

All replies

  • I could find no authoritative statement that says that FSW doesn't work through junction points.  I'm not surprised it doesn't, your findings are convincing to me.  As is the workaround you used.
    Friday, April 6, 2007 5:38 PM
  • FileSystemWatcher is implemented with ReadDirectoryChangesW, which is documented with

    To track changes on a volume, see change journals.

    A "volume" is also known as a Volume Mount Point, reparse, or junction point.

     

    Although, not very explicit, it sounds like ReadDirectoryChangesW does not support junction points.

    Saturday, April 7, 2007 9:17 AM
  • Thanks for the answers, my work-around seems to work well enough..just a shame I couldn't use just one FSW ;/
    Saturday, April 7, 2007 10:49 AM