I have various files which I've created as hardlinks to others using mklink. I need a command I can use inside a batch file to determine which files in a given directory have only one link to it. I know fsutil hardlink list
can show me the links, but I need to be able to run the batch file as a regular user, whereas the above command won't run without admin rights. I'm looking for a way to do this without installing third-party applications.
Asked
Active
Viewed 3,153 times
4

Display Name
- 761
- 1
- 8
- 13
2 Answers
3
I don't know of any way in batch off hand, but for PowerShell, the Win32 API function GetFileInformationByHandle returns the BY_HANDLE_FILE_INFORMATION structure, which contains the nNumberOfLinks
member, which is a numerical value indicating the number of hardlinks to the file. (1
means no hard links, so the number returned is the number of hard links + 1).

HopelessN00b
- 53,795
- 33
- 135
- 209
-
1It might not matter a great deal but I assume that it's not actually the case that `nNumberOfLinks` is "the number of hard links + 1" but rather that the original filename counts as the first hard link. – Håkan Lindqvist Feb 27 '16 at 14:56
2
FindLinks from Sysinternals is an alternative to fsutil that will show you hard links. https://docs.microsoft.com/en-us/sysinternals/downloads/findlinks

Sam Rueby
- 656
- 3
- 8
- 17