FindFirstFile error on root path

I use the following code to get file system directory information:

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 the root path:

  • D:\ - error code ERROR_FILE_NOT_FOUND
  • D: - error code ERROR_FILE_NOT_FOUND
  • \\SRVR-1\share - error code ERROR_BAD_NET_NAME
  • \\SRVR-1\share\ - error code ERROR_BAD_NET_NAME
  • \\SRVR-1\HiddenShare$ - error code ERROR_BAD_NET_NAME

But it works in the following cases:

  • D:\1 - no mistakes
  • \\SRVR-1\share\1 - no mistakes
  • \\SRVR-1\HiddenShare$\1 - no mistakes

Any idea why?

+3
source share
1 answer

FindFirstFile()intended for listing the contents of a directory. As such, it is intended to be used with a file template, for example D:\*.

When you use D:\1, you simply use a very strict file template ( 1) to filter the files in D:\, but when using only D:\or the D:template at all

. , \\SRV-1\share , \\SRV-1 .

+4

All Articles