BUG: FindFirstFile() Does Not Handle Wildcard (?) Correctly

ID: Q130860


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), included with:
    • Microsoft Windows 95


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.

Additional query words: 4.00 regular expression wild

Keywords : kbWinOS95bug
Version : winnt:
Platform : winnt
Issue type :


Last Reviewed: September 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.