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.

其他提示

Try dropping the trailing slash:

L"\\\\.\\C:"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top