BUG: FindFirstFile() Does Not Handle Wildcard (?) CorrectlyLast reviewed: September 25, 1995Article ID: Q130860 |
The information in this article applies to:
SYMPTOMSIn 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.
RESOLUTIONTo 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).
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
|
Additional reference words: 95 4.00 regular expression wild
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |