5

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.

2 Answers2

4

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
  • 686
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
  • 54,273