2

Is there a way to get a file hardlinks count on Windows without using GetFileInformationByHandle()?

MSDN says:

Depending on the underlying network features of the operating system and the type of server connected to, the GetFileInformationByHandle function may fail, return partial information, or full information for the given file.

In practice, retrieving the link count on a network share, whatever the Windows version at both ends, always return 1. The only case where it works is when accessing a samba share. Looks like they forgot to duplicate Windows bug/limitation. Also, the "partial results" without telling you they are partial is pretty nice for an API call.

skaffman
  • 398,947
  • 96
  • 818
  • 769
pmezard
  • 427
  • 3
  • 11

2 Answers2

1

For that you can try FindFirstFileNameW and FindNextFileNameW.

It isn't good option to enumerate stuff to get count but it is another way.

ST3
  • 8,826
  • 3
  • 68
  • 92
1

It seems a little strange but what about GetFileInformationByHandleEx. It doesn't contain the waiver that you quoted above, so perhaps has the smarts built into it to handle some of the problems that GetFileInformationByHandle can have.

torak
  • 5,684
  • 21
  • 25
  • Unfortunately I don't have any Vista/2008 underhand and I need support for everything >= Win2000 (should have said it in the question, sorry). – pmezard Aug 19 '10 at 15:46
  • -1 `GetFileInformationByHandleEx` contains the same waiver "Certain file information classes behave slightly differently on different operating system releases. These classes are supported **by the underlying drivers**, and any information they return is subject to change between operating system releases." – unixman83 Sep 13 '11 at 11:17