Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFileFind Problem. Don't search the Subdirs. [Solved]

CFileFind Problem. Don't search the Subdirs. [Solved]

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fantasy1215
    wrote on last edited by
    #1

    My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.

    void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
    {
    CFileFind finder;
    TCHAR szWildcard[MAX_PATH] = {0};
    _sntprintf(szWildcard, MAX_PATH, _T("%s"), path);

    PathAppend(szWildcard, \_T("\*.txt"));
    BOOL bWorking = finder.FindFile(szWildcard);
    while (bWorking)
    {
    	bWorking = finder.FindNextFile();
    
    	//1 escape dot
    	if (finder.IsDots())
    		continue;
    	if (finder.IsDirectory())
    	{
    		SearchInternal(finder.GetFilePath(), file);
    	}
    	//else is a file
    	//Do my things here
    	
    }
    finder.Close();
    

    }

    modified on Saturday, September 20, 2008 9:51 PM

    H M 2 Replies Last reply
    0
    • F fantasy1215

      My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.

      void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
      {
      CFileFind finder;
      TCHAR szWildcard[MAX_PATH] = {0};
      _sntprintf(szWildcard, MAX_PATH, _T("%s"), path);

      PathAppend(szWildcard, \_T("\*.txt"));
      BOOL bWorking = finder.FindFile(szWildcard);
      while (bWorking)
      {
      	bWorking = finder.FindNextFile();
      
      	//1 escape dot
      	if (finder.IsDots())
      		continue;
      	if (finder.IsDirectory())
      	{
      		SearchInternal(finder.GetFilePath(), file);
      	}
      	//else is a file
      	//Do my things here
      	
      }
      finder.Close();
      

      }

      modified on Saturday, September 20, 2008 9:51 PM

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      OF course except CfileFind you can use of FindFirstFile/FindNextFile.

      1 Reply Last reply
      0
      • F fantasy1215

        My directory structure is Dir1 |---------file.exe |---------angle.txt |---------test.txt |---------Dir2 |________Dir3 My code works like it just find the .txt files under Dir1, never find files under Dir2, Dir3 etc. Please tell me what's wrong with my code.

        void CWinSearchDlg::SearchInternal(LPCTSTR path, CStdioFile *file)
        {
        CFileFind finder;
        TCHAR szWildcard[MAX_PATH] = {0};
        _sntprintf(szWildcard, MAX_PATH, _T("%s"), path);

        PathAppend(szWildcard, \_T("\*.txt"));
        BOOL bWorking = finder.FindFile(szWildcard);
        while (bWorking)
        {
        	bWorking = finder.FindNextFile();
        
        	//1 escape dot
        	if (finder.IsDots())
        		continue;
        	if (finder.IsDirectory())
        	{
        		SearchInternal(finder.GetFilePath(), file);
        	}
        	//else is a file
        	//Do my things here
        	
        }
        finder.Close();
        

        }

        modified on Saturday, September 20, 2008 9:51 PM

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        fantasy1215 wrote:

        Please tell me what's wrong with my code.

        Your wildcard is "*.txt". Your subdirectories don't have a .txt extension so they won't show up in the search. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        F 1 Reply Last reply
        0
        • M Mark Salsbery

          fantasy1215 wrote:

          Please tell me what's wrong with my code.

          Your wildcard is "*.txt". Your subdirectories don't have a .txt extension so they won't show up in the search. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          F Offline
          F Offline
          fantasy1215
          wrote on last edited by
          #4

          There are .txt files in Subdirs too.

          B 1 Reply Last reply
          0
          • F fantasy1215

            There are .txt files in Subdirs too.

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            But the SubDirs will be Ignored because they do not have a '.txt' extension in their name. (For Still the best explanation about Command Line Parsing Rules, Look up any book about DOS 6.00). DOS may have died, but many of its parsing rules persist. :)

            Bram van Kampen

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups