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.


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).

  • It 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

FindLinks from Sysinternals is an alternative to fsutil that will show you hard links. https://docs.microsoft.com/en-us/sysinternals/downloads/findlinks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.