通常,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/