0

I'm writing an app in Qt and trying to use the windows functions FindFirstFile and FindNextFile in order to speed up counting large numbers of files in several directories. I've copied this code almost verbatum off the microsoft site in order to list files, but debugging it shows that it's only listing one file when I trigger the function;

QStringList Manager::returnDirectoryFileData(QString ChangedDirectory)
{
    QStringList DirectoryFiles;
    WIN32_FIND_DATA FindFileData;
    LARGE_INTEGER filesize;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    DWORD dwError = 0;

    //string directorySearch = "E:\\My Documents\\Visual Studio 2010\\Projects\\SEP-Asignment-One\\Debug\\*";

    // Find the first file in the directory.
    LPCWSTR ConvertedDir = (const wchar_t*)ChangedDirectory.utf16();
    PVOID OldValue = NULL;

    if (Wow64DisableWow64FsRedirection(&OldValue))
    {
        hFind = FindFirstFile(ConvertedDir, &FindFileData);

        if (hFind == INVALID_HANDLE_VALUE)
        {
            printf("Invalid file handle. Error is %u.\n", GetLastError());
        }

        do
        {
            QString Newname = "Want to do stuff here";
            DirectoryFiles.append(Newname);

            printf("  %s   <DIR>\n", FindFileData.cFileName);

        } while (FindNextFile(hFind, &FindFileData) != 0);

        dwError = GetLastError();
        if (dwError != ERROR_NO_MORE_FILES)
        {
            DisplayErrorBox(TEXT("FindFirstFile"));
        }

        FindClose(hFind);

    }
    Wow64RevertWow64FsRedirection(&OldValue);
    return DirectoryFiles;
}       

This is a 32 bit program running on 64 bit windows 10, so the Wow64DisableWow64fsredirection is supposed to be called before these functions are used. Anyone know what I'm doing wrong? Thanks!

Robbie Cooper
  • 483
  • 2
  • 5
  • 13

0 Answers0