Search code examples
c++winapintfs

GetFileAttributes inconsistency -- why?


Why does the following:

GetFileAttributes(L"D:");

return 0x00002010, but the following on the exact same machine:

GetFileAttributes(L"\\\\?\\D:");

returns INVALID_FILE_ATTRIBUTES and error code ERROR_INVALID_PARAMETER?


Solution

  • The three examples you give in the question and comments all refer to different things.

    • \\?\D: refers to a volume, for which file attributes do not exist.
    • \\?\D:\ is the root directory of the drive which does have attributes.
    • D: is a little harder to define. I believe that the system uses GetFullPathName, or equivalent, to expand this path. So, if the process current directory is on D, then that directory is used. Or, if a special per-drive working directory environment variable is defined for this drive, that directory is used. Otherwise D:\, the root directory is used.

    You want to be using D:\ or \\?\D:\ here.