Thread: How to get this code to loop through multiple directories...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    673

    How to get this code to loop through multiple directories...

    I have the following code, and it works fine, but I want it to go through all the directories in the target folder.
    This is the code...
    Code:
    void TestClass::FindFiles(const std::string &directory, const std::string &types)
    {
        _WIN32_FIND_DATAA* FindFileData = new _WIN32_FIND_DATAA;
        HANDLE hFind;
    
        if ( Debug )
            printf("Target: %s\n", directory.c_str());
        
        //Find First file
        hFind = FindFirstFileA(directory.c_str(), FindFileData);
        if ( hFind == INVALID_HANDLE_VALUE )
            printf("Invalid File Handle. Error# %d\n", GetLastError());
        else
            files.push_back((char*)FindFileData->cFileName);
            if ( Debug )
                printf("Found: %s\n", FindFileData->cFileName);
    
        //Find the next files
        while ( FindNextFileA(hFind, FindFileData) != 0 )
        {
            files.push_back((char*)FindFileData->cFileName);
            if ( Debug )
                printf("Found: %s\n", FindFileData->cFileName);
        }
        FindClose(hFind);
        delete FindFileData;
    }
    Thank you for any advice.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could look in the FAQ.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While loop with multiple characters
    By arctic_blizzard in forum C Programming
    Replies: 16
    Last Post: 09-20-2008, 12:25 PM
  2. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  3. Multiple conditions for the while loop?
    By Olidivera in forum C++ Programming
    Replies: 6
    Last Post: 04-24-2005, 03:47 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM