NTFS 中的获取文件属性

发布于 2024-12-18 07:44:46 字数 233 浏览 3 评论 0原文

我想使用 Windows API 来检查文件/目录是否隐藏。 GetFileAttributes 可能是最好的选择。但当我检查 FAT“C:\”时,它返回 0x10。它看起来运行良好。但在NTFS“C:\”中返回0x16,可能表明“C:\”的属性是“系统”、“目录”和“隐藏”。那么问题来了,为什么它的返回隐藏呢?事实上它并没有隐藏。

您能给我另一个 API 来检查 Windows 文件系统的文件/目录是否隐藏吗? 多谢。

i want to use a windows API to check a file/directory is hidden or not .
GetFileAttributes may the best choice. but when i check the FAT "C:\", it's return 0x10.it's looks work well. but in NTFS "C:\" it's return 0x16, maybe it's show that "C:\"'S Attribute is "system", "directory",and "hidden". so the problem is here, why it's return hidden? in fact it's not hidden.

would you please give me another API to check the windows file system's file/directory is hidden or not?
thanks a lot.

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

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

发布评论

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

评论(1

魂归处 2024-12-25 07:44:46

GetFileAttributes 有一个很大的 BUG,要查看它,请尝试这个简单的代码:

ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.MyNonExistantFile'))));

它表明 GetFileAttributes 返回了十进制的 32(因为文件不存在,所以这是一个 BUG,正确的返回值必须是 -1)。

您也可以尝试一下:

CreateDir('C:\.Anything');
ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.Anything\MyNonExistantFile.TXT'))));

它与以句点(.)符号开头的文件和目录相关。

注意:在这种情况下,FileExists 也会返回 true(并且文件不存在)。

GetFileAttributes has a BIG BUG, to see it try this simple code:

ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.MyNonExistantFile'))));

It shows that GetFileAttributes has return 32 in decimal (since file does not exists it is a BUG, correct return value must be -1).

Also you can try it with this:

CreateDir('C:\.Anything');
ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.Anything\MyNonExistantFile.TXT'))));

It is related with files and directories starting by a period (.) symbol.

Note: FileExists also returns true in that situations (and file does not exists).

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