Wildcards! Which one?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Wildcards! Which one?

  1. #1
    Join Date
    Jun 2013
    Posts
    21

    Wildcards! Which one?

    Im working on a simple file list program that list folders and files using CFileFind. Heres how the program goes!
    1. User types a directory in a edit box
    2. Presses button and files and folders get listed.

    **If user wants to go back a directory

    1. Presses the back button


    And the back button is my problem. I know the problem is the Wildcard format. Im using a CString with a addition "/.." eg....(CString cp = m_Directory + "/..");
    I tried CString cp = m_Directory + "/.." + "*.*" and vice versa with no luck
    My question is how do I add a "*.*" to the CString cp? If I don't add "*.*", I know that all the files will not get listed.Only one folder gets listed when I press the back button

    Can you help me with this problem.

    -THX

    oh yeah. Here is the code im using for the back button



    Code:
    void CAlDlg::OnButton1() 
    {
    		m_b.ResetContent();
    
    UpdateData(true);
    CString oke = m_o;
    UpdateData(false);
    
    
     CFileFind OneFile; 
     CString FileName, DirName; 
     BOOL BeWorking; 
    
     DirName = oke + "/.."; 
     BeWorking = OneFile.FindFile (DirName); 
     while (BeWorking) 
     { 
     BeWorking = OneFile.FindNextFile () ;
     if (OneFile.IsDots ()) continue;  
    
    	m_b.AddString(OneFile.GetFileName ());
    
    
    GetDlgItem(IDC_EDIT3)->SetWindowText(OneFile.GetRoot());
    
    
     
     } 
     OneFile.Close (); 
    	
    	
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: Wildcards! Which one?

    See the example for CFileFind::IsDirectory
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2013
    Posts
    21

    Re: Wildcards! Which one?

    Dang, man its hard...even looked up the IsDirectory on msdn with no luck
    heres some code that I came up...jerry rigging and still does not work entirely..i get double folders of the directory im in.

    Code:
    void CAlDlg::OnButton1() 
    {
    		m_b.ResetContent();
    
    UpdateData(true);
    CString oke = m_o;
    UpdateData(false);
    
    
     CFileFind OneFile; 
     CString FileName, DirName; 
     BOOL BeWorking; 
    
     DirName = oke + ".."; 
     BeWorking = OneFile.FindFile (DirName); 
     while (BeWorking) 
     {  BeWorking = OneFile.FindNextFile () ;
    	 if(OneFile.IsDirectory() && OneFile.IsDots())
    	 {
    		 
    		 	m_b.ResetContent();
    		 
    		 
    	 }
     
    
    	m_b.AddString(OneFile.GetFileName ());
    
    
    GetDlgItem(IDC_EDIT3)->SetWindowText(OneFile.GetRoot());
    
    
    UpdateData(true);
    
    
    
    BeWorking = OneFile.FindFile (m_o + "\\*.*"); 
     while (BeWorking) 
     { 
    	 
     BeWorking = OneFile.FindNextFile () ;
     
    
    	m_b.AddString(OneFile.GetFileName ());
    
    
    
     }
    
    
    UpdateData(false);
    
    
    
    
    
     } 
     OneFile.Close (); 
    	
    	
    }
    Can someone tell me the proper way of getting the back button to work, to list all files.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: Wildcards! Which one?

    From MSDN:
    Example
    This small program recurses every directory on the C:\ drive and prints the name of the directory.
    Code:
    #include <afxwin.h>
    #include <iostream>
    
    using namespace std;
    
    void Recurse(LPCTSTR pstr)
    {
       CFileFind finder;
    
       // build a string with wildcards
       CString strWildcard(pstr);
       strWildcard += _T("\\*.*");
    
       // start working for files
       BOOL bWorking = finder.FindFile(strWildcard);
    
       while (bWorking)
       {
          bWorking = finder.FindNextFile();
    
          // skip . and .. files; otherwise, we'd
          // recur infinitely!
    
          if (finder.IsDots())
             continue;
    
          // if it's a directory, recursively search it
    
          if (finder.IsDirectory())
          {
             CString str = finder.GetFilePath();
             cout << (LPCTSTR) str << endl;
             Recurse(str);
          }
       }
    
       finder.Close();
    }
    
    int main()
    {
       if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
          cout << "panic!" << endl;
       else
          Recurse(_T("C:"));
    }
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Wildcards! Which one?

    Quote Originally Posted by vaas View Post
    Dang, man its hard...even looked up the IsDirectory on msdn with no luck
    heres some code that I came up...jerry rigging and still does not work entirely..i get double folders of the directory im in.
    One suggestion to make to you is that you first write simple programs that perform the basic task you're looking for.

    Your code is a jumble of listbox calls, button calls, and other things totally unrelated with writing a function that recurses through a directory, causing confusion, not only to you, but it clutters the code so that others helping you have to filter out the unnecessary noise.

    If you take a look at Victor's example, that is exactly what you should be writing first, making sure you are familiar and know how to use the CFileFind class. Once you know how to properly use it, then you apply it to the larger program.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center