c00000fd
c00000fd

Reputation: 22255

FindFirstFile fails on the root path

I'm using the following code to obtain information about a file system directory:

LPCTSTR pStrPath = L"D:\\1";
WIN32_FIND_DATA wfd;
HANDLE hDummy = ::FindFirstFile(pStrPath, &wfd);
if(hDummy != INVALID_HANDLE_VALUE)
{
    //Use 'wfd' info
    //...

    ::FindClose(hDummy);
}
else
{
    int error = ::GetLastError();
}

The code works just fine, unless I specify a root path:

But it works in the following cases:

Any idea why?

Upvotes: 5

Views: 3865

Answers (1)

rodrigo
rodrigo

Reputation: 98328

FindFirstFile() is meant to be used to enumerate the contents of a directory. As such it is meant to be used with a file pattern, such as D:\*.

When you use D:\1 you are just using a very restrictive file pattern (1) to filter the files in D:\, but when you use just D:\ or D: there is no pattern at all!

And the same is true for shared resources. Note that \\SRV-1\share does not count as a pattern, because \\SRV-1 cannot be considered a directory.

Upvotes: 7

Related Questions