GetFileAttributes inconsistency -- why?

1

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?

c++
winapi
ntfs
asked on Stack Overflow Jun 23, 2014 by c00000fd

1 Answer

6

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.

answered on Stack Overflow Jun 23, 2014 by David Heffernan • edited Jun 23, 2014 by David Heffernan

User contributions licensed under CC BY-SA 3.0