c++ - 为什么 GetFileAttributesW(L"C :") return FILE_ATTRIBUTE_REPARSE_POINT?

标签 c++ windows winapi boost

通常,GetFileAttributesW(L"C:") 返回0x10 (FILE_ATTRIBUTE_DIRECTORY),这是合理的。

在某些情况下,GetFileAttributesW(L"C:") 将返回 0x2416(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)

我想知道是什么让它发生以及如何摆脱它。这个问题使得 boost::filesystem::canonical 无法工作。你有什么主意吗?

最佳答案

这里主要的混淆是C: 的意思。这被解释为 C 驱动器上的当前目录。这在 MSDN 上有解释:Naming Files, Paths, and Namespaces .

If a file name begins with only a disk designator but not the backslash after the colon, it is interpreted as a relative path to the current directory on the drive with the specified letter. Note that the current directory may or may not be the root directory depending on what it was set to during the most recent "change directory" operation on that disk. Examples of this format are as follows:

  • "C:tmp.txt" refers to a file named "tmp.txt" in the current directory on drive C.
  • "C:tempdir\tmp.txt" refers to a file in a subdirectory to the current directory on drive C.

因此 GetFileAttributesW(L"C:") 返回的值取决于当前目录是什么。我相信您打算获取根文件夹的属性,在这种情况下,您必须使用 GetFileAttributesW(L"C:\\")

关于c++ - 为什么 GetFileAttributesW(L"C :") return FILE_ATTRIBUTE_REPARSE_POINT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38300808/

相关文章:

windows - Mongodb Windows 安装程序 "admin web console waiting for connections on port 28017"错误

c++ - 如何使用RAWKEYBOARD中的ExtraInformation?

c++ - 是否可以强制/检测锁顺序以防止死锁?

delphi - 使用 WinAPI 将击键发送到另一个应用程序

c++ - 生成运行时递归调用树的工具

c++ - 如何在 OpenGL/GLSL 中对特定颜色进行阈值处理

c++ - 使用自定义消息防止 Windows 关机

windows - 无法从 WinPE 内的 Windows 8 安装中完全删除 ProgramData

linux - 与库交叉编译

c++ - 如何在 Ubuntu 14.04 中安装 Qt 3.3.8