1

Lets suppose that there are:

  • a folder and
  • a junction point or a symlink to that folder

When the original folder is moved to a new location, both the junction point and the symlink fail (point to an orphaned location). The failure of the link is not the case when a hard link to a file is created. Any hard link to a file can be moved to other folders and it will still point to the same physical file on the hard drive.

Is there a way to create a 'link' to a folder, so that when the folder is moved, the link 'tracks' the location of that folder and still works after the move operation?

If not, why is this not possible.

colemik
  • 749
  • 1
  • 12
  • 24

1 Answers1

2

You can use junction.exe from the SysInternals suite to create hard links to directories in XP.

Creating hardlinks to files can be done natively, with the fsutils (command line) utility.

However, what you're asking for doesn't exist in NTFS. I found a decent rundown of the NTFS implementations of Hard Links, Junction Points, and Soft Links, but as far as what you're asking about, junction points are the directory/folder version of file hard links under NTFS. And, unlike hard links, they will not update if their target is moved or removed. As to why this is the case, because that's the way Microsoft chose to implement junction points in their file system.

Per Michael Hampton's comment, I did a little Googling about directory hard links, and while I couldn't find anything immediately from Microsoft as it relates to true hard links creating loops in the directory structure, I did find something from Unix and Linux .SE with a good explanation of the problem, and the fundamentals are the same, so it might be worth a read.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
  • Thanks for the response. According to what I've read, `junction.exe` can only create _junction points_ to directories and `fsutil` can only create hard links to _files_. There is no way to create a hard link to a _folder_ with those tools. – colemik Feb 17 '14 at 17:13
  • @trismarck A junction point (in NTFS) *is* a hardlink to a directory. To my knowledge, that's as good as it gets. My apologies for not reading your question thoroughly enough, but I'll update my answer. – HopelessN00b Feb 17 '14 at 17:20
  • @@HopelessN00b yes, the nomenclature on the subject of 'links' to files on the filesystem is 'hard to discern'. One could name a hard link a link that is 'transparent' for the underlying application (the filesystem transparently reparses the destination path once it hits a hard link) and one could name a hard link a link that is able to 'track' the location of the target folder the link points to, when the location of that target folder changes. I'm after the second case. That's why there is `trackable` and `~` in the topic of the question. Thanks for clearing that up. – colemik Feb 17 '14 at 17:31
  • 2
    True hard links to directories aren't allowed because they would create infinite loops in the directory structure. – Michael Hampton Feb 17 '14 at 17:48
  • @MichaelHampton just to clear this out, it _is already_ possible to create infinite loops in the directory structure by using just junction points. See Link Shell Extension: http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html . – colemik Feb 17 '14 at 19:50
  • @trismarck I believe the difference is that junction points can be differentiated from their targets (like soft links), whereas a true hard link cannot. That so many applications and utilities in Windows *don't* check for the difference is a different problem. But it is possible to check for the difference, as (for example) robocopy does via the `/XJ` switch. – HopelessN00b Feb 17 '14 at 19:55
  • @trismarck Not really. A junction is just a variant of a _symbolic_ link, not a hard link. So it doesn't really create a loop in the directory structure. – Michael Hampton Feb 17 '14 at 19:55
  • @MichaelHampton it does (tested). I.e. if, inside of a folder `a`, I create a junction point named `b` that points to the folder `a`, I have an infinite loop. But perhaps you're referring to some other mechanism? – colemik Feb 17 '14 at 19:58
  • @trismarck He's talking about at the file system level. Sure, you can create a loop in your folders with junction points, shortcuts, and probably other methods, but this does not create a loop at a file system level because soft links are different than their targets. True hard links are not. Read the link to U&L I included in my most recent edit for more details. – HopelessN00b Feb 17 '14 at 20:21