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:
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 error\\SRVR-1\share\1
- no error\\SRVR-1\HiddenShare$\1
- no errorAny idea why?
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.
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