BUG: FindFirstFile() Does Not Handle Wildcard (?) Correctly (130860)
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API), when used with:
This article was previously published under Q130860 SYMPTOMS
In Windows 95, the FindFirstFile() function interprets a wildcard (?) as
"any character" instead of "zero or one character," its true meaning. This
incorrect interpretation causes some searches to return invalid results.
For example, if the files, TEMP.TXT and TEMPTEMP.TXT, are in the same
directory, the following code finds the TEMPTEMP.TXT file, but not the
TEMP.TXT file:
HANDLE hFind;
WIN32_FIND_DATA findData = {0};
hFind = FindFirstFile ("TEM?????.???", &findData);
if (hFind == INVALID_HANDLE_VALUE)
MessageBox (hwnd, "FindFirstFile() failed.", NULL, MB_OK);
else
{
do
{
MessageBox (hwnd, findData.cFileName, "File found", MB_OK);
}
while (FindNextFile(hFind, &findData));
CloseHandle (hFind);
}
Windows NT correctly finds both the TEMP.TXT and TEMPTEMP.TXT files.
RESOLUTION
To work around this problem, choose an alternative wildcard search and
apply further processing to eliminate files that are found by the
alternative search, but do not match the original search. For example, the
code above could be changed to search for TEM*.* instead of TEM?????.???.
Then you could make an additional test for filenames that are up to 8
characters in length, followed by a ".", followed by up to 3 more
characters (8.3).
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 3/7/2005 |
---|
Keywords: | kbBug KB130860 |
---|
|