Thread: Get files list from subdirs

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    35

    Get files list from subdirs

    Hi all! I use WTL + winapi. I need to obtain a list of files from a specified directory, including files from all subdirectories. I wrote a function, but it doesn't work correcty...
    We start to search files, when we found an subdir, we set it as current direcotory, and call recursively my function for that dir. But when I'm turning back to root dir, it starts from beginnig, but doesn't continue the search, by skiping last founded subdir.
    Here is the code:
    Code:
    void GetAllFiles(char* str, CListBox cLb)
    {
    	HANDLE hSearch = NULL;
    	WIN32_FIND_DATA wfd;
    
    	SetCurrentDirectory(str);
    	::MessageBox(NULL, str, "CurDir", 0);
    
      for (hSearch = FindFirstFile("*.*", &wfd); FindNextFile(hSearch, &wfd);)
      {
    		if (strcmp(wfd.cFileName, ".") == 0) continue;   /* current dir */
    		if (strcmp(wfd.cFileName, "..") == 0) continue;  /* parent dir  */
    
    		if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    		{
    			strcat(str, "\\");
    			strcat(str, wfd.cFileName);
    			::MessageBox(NULL, str, "Folder::  ", 0);
    			GetAllFiles(str, cLb);
    		}
    
    		cLb.InsertString(0, wfd.cFileName);
    	}
    
    	if( strcmp(str, szFolderPath) )//Esli nado vyshe
    	{	
    		str[ strlen(str) - strlen(wfd.cFileName) ] = '\0';
    		GetAllFiles(str, cLb);
    	}
    return;
    }
    Thx for your answers!
    im from LMoldovaZ

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Maybe the one in the FAQ will help you?
    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.

  3. #3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 12:30 PM
  3. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 01:13 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM