Get files list from subdirs

This is a discussion on Get files list from subdirs within the Windows Programming forums, part of the Platform Specific Boards category; Hi all! I use WTL + winapi. I need to obtain a list of files from a specified directory, including ...

  1. #1
    LMZ
    LMZ is offline
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

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, 03:09 AM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 11:30 AM
  3. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 12: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21