How can I programmatically distinguish hard links from real files in Windows 7?

别说谁变了你拦得住时间么 提交于 2019-12-06 04:06:57

You can't, because all files are hard links. No. Really. A file is just a hard link to a data chunk -- a listing in a directory. (Perhaps you mean symlinks? You can distinguish those...)

Use the builtin methods Windows provides for calculating used space instead.

EDIT: Reference (emphasis mine)

The link itself is only a directory entry, and does not have a security descriptor. Therefore, when you change the security descriptor of a hard link, you a change the security descriptor of the underlying file, and all hard links that point to the file allow the newly specified access.

You can't distinguish hard links from "real files". The directory entry for a "real file" is just another hard link. Perhaps you meant a symbolic link.

POSIX has a stat function (called _stat in Windows) that can detect multiple links to the same file, which will have the same "inode" number.

Use GetFileInformationByHandle() and check the returned BY_HANDLE_FILE_INFORMATION nNumberOfLinks member for a value > 1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!