The MSDN page on CreateFile says: The string "\\.\C:\"
can be used to open the file system of the C: volume. However, the following code always returns an error : ERROR_PATH_NOT_FOUND.
HANDLE h = CreateFile(L"\\\\.\\C:\\", FILE_READ_ATTRIBUTES,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0);
How should I pass the arguments correctly?
If you wanted a volume handle (for use with I/O control codes) you would have needed to drop the trailing slash.
In order to get a handle to the root directory, you need to keep the trailing slash and pass the FILE_FLAG_BACKUP_SEMANTICS
flag in the dwFlagsAndAttributes
argument. This is documented on the MSDN page under the heading "Directories". For example, this is what you want to do if you're planning to call GetFileInformationByHandle
or GetFileInformationByHandleEx
.
Ordinarily, however, you wouldn't open a handle to the root directory in order to list the files. Instead, you would use FindFirstFile
/FindNextFile
or one of the related functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With