Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GetFileAttributesW(L"C:") return FILE_ATTRIBUTE_REPARSE_POINT?

Normally, GetFileAttributesW(L"C:") returns 0x10 (FILE_ATTRIBUTE_DIRECTORY), which is reasonable.

In some case, GetFileAttributesW(L"C:") will return 0x2416 (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)

I wonder what makes it happen and how to get rid of it. This issue makes boost::filesystem::canonical can't work. Do you have any idea?

like image 992
P.X Avatar asked Apr 26 '26 10:04

P.X


1 Answers

The main confusion here is what C: means. This is interpreted as being the current directory on the C drive. This is explained over on 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.

So the value returned by GetFileAttributesW(L"C:") depends on what the current directory is. I believe that you are intending to obtain the attributes of the root folder, in which case you must use GetFileAttributesW(L"C:\\").

like image 160
David Heffernan Avatar answered Apr 29 '26 02:04

David Heffernan