Question

I'm currently searching for a C# solution which can read the number of hardlinks of a file and their links locations. I'm thinking of the program link shell extension which can do this by going to the file properties and lists all the hardlinks of one file. I expect there is a solution for C# coders which can do the same without searching through the complete disk.

Edit 1:

Is there a way to test two HardLinks if they are the same file?

Was it helpful?

Solution

To get the link count, use GetFileInformationByHandle and access the NumberOfLinks member.

Here's an example of using the API in VB: http://blogs.msdn.com/b/vbteam/archive/2008/09/22/to-compare-two-filenames-lucian-wischik.aspx

To find the names of all the links, you need to use FindFirstFileNameW but it's only available as of Vista (or Server 2k8), and I can't find P/Invoke information for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top