无需 GetFileInformationByHandle() 即可获取 Windows 硬链接计数

发布于 2024-09-14 18:10:30 字数 340 浏览 4 评论 0原文

有没有一种方法可以在不使用 GetFileInformationByHandle() 的情况下在 Windows 上获取文件硬链接计数?

MSDN 说:

根据操作系统的底层网络功能和连接的服务器类型,GetFileInformationByHandle 函数可能会失败、返回给定文件的部分信息或完整信息。

实际上,检索网络共享上的链接计数,无论两端的 Windows 版本如何,始终返回 1。它唯一起作用的情况是访问 samba 共享时。看起来他们忘记复制 Windows 错误/限制。此外,“部分结果”而不告诉您它们是部分结果对于 API 调用来说非常好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-09-21 18:10:30

这看起来有点奇怪,但是 GetFileInformationByHandleEx< 怎么样? /代码>。它不包含您上面引用的豁免,因此也许内置了智能功能来处理 GetFileInformationByHandle 可能遇到的一些问题。

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.

为此,您可以尝试 FindFirstFileNameW< /a> 和 FindNextFileNameW。

枚举东西来计数并不是一个好的选择,但这是另一种方式。

For that you can try FindFirstFileNameW and FindNextFileNameW.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文