Alex Rivera | Logout

FindNextFile fails on 64-bit Windows?

Asked 2008-09-18T19:20:33.083
11

using C++Builder 2007, the FindFirstFile and FindNextFile functions doesn't seem to be able to find some files on 64-bit versions of Vista and XP. My test application is 32-bit.

If I use them to iterate through the folder C:\Windows\System32\Drivers they only find a handful of files although there are 185 when I issue a dir command in a command prompt. Using the same example code lists all files fine on a 32-bit version of XP.

Here is a small example program:

int main(int argc, char* argv[])
{
  HANDLE hFind;
  WIN32_FIND_DATA FindData;
  int ErrorCode;
  bool cont = true;

  cout << "FindFirst/Next demo." << endl << endl;

  hFind = FindFirstFile("*.*", &FindData);
  if(hFind == INVALID_HANDLE_VALUE)
  {
    ErrorCode = GetLastError();
    if (ErrorCode == ERROR_FILE_NOT_FOUND)
    {
      cout << "There are no files matching that path/mask\n" << endl;
    }
    else
    {
      cout << "FindFirstFile() returned error code " << ErrorCode << endl;
    }
    cont = false;
  }
  else
  {
    cout << FindData.cFileName << endl;
  }

  if (cont)
  {
    while (FindNextFile(hFind, &FindData))
    {
      cout << FindData.cFileName << endl;
    }

    ErrorCode = GetLastError();
    if (ErrorCode == ERROR_NO_MORE_FILES)
    {
      cout << endl << "All files logged." << endl;
    }
    else
    {
      cout << "FindNextFile() returned error code " << ErrorCode << endl;
    }

    if (!FindClose(hFind))
    {
      ErrorCode = GetLastError();
      cout << "FindClose() returned error code " << ErrorCode << endl;
    }
  }
  return 0;
}

Running it in the C:\Windows\System32\Drivers folder on 64-bit XP returns this:

C:\WINDOWS\system32\drivers>t:\Project1.exe
FindFirst/Next demo.

.
..
AsIO.sys
ASUSHWIO.SYS
hfile.txt
raspti.zip
stcp2v30.sys
truecrypt.sys

All files logged.
Edit
Report

1 Answer

0

Are you sure it is looking in the same directory as the dir command? They don't seem to have any files in common.

Also, this isn't the issue, but the correct wild card for "all files" is *

*.* means "all files with at least one . in the name"

answered 2008-09-18T19:25:53.027

Your Answer