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. How to list a file in a particular directory?

How to list a file in a particular directory?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, I'm using CFileFind to search files: CListBox* pListBox = (CListBox*)GetDlgItem(IDC_FILE_LISTING); pListBox->ResetContent(); CFileFind finder; CString extension = "*.scr"; CString filepath = ""; BOOL haveFile = finder.FindFile(extension); while (haveFile) { haveFile = finder.FindNextFile(); pListBox->AddString((LPCTSTR)finder.GetFileTitle()); } I want to make it to search for a directory...for example, search c:\abc\cde\*.scr, where my program.exe file is in c:\abc....how can i do that?

    L M 2 Replies Last reply
    0
    • L Lost User

      Hi, I'm using CFileFind to search files: CListBox* pListBox = (CListBox*)GetDlgItem(IDC_FILE_LISTING); pListBox->ResetContent(); CFileFind finder; CString extension = "*.scr"; CString filepath = ""; BOOL haveFile = finder.FindFile(extension); while (haveFile) { haveFile = finder.FindNextFile(); pListBox->AddString((LPCTSTR)finder.GetFileTitle()); } I want to make it to search for a directory...for example, search c:\abc\cde\*.scr, where my program.exe file is in c:\abc....how can i do that?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      To get the directory where your program is located : void GetLaunchedDir(CString& strLaunched) { TCHAR szFullPath[MAX_PATH]; TCHAR szDir[_MAX_DIR]; TCHAR szDrive[_MAX_DRIVE]; // // get apps full path // ::GetModuleFileName(NULL,szFullPath,MAX_PATH); // // break full path into separate components _splitpath(szFullPath, szDrive, szDir, NULL, NULL); // // Store apps drive and path strLaunched.Format(_T("%s%s"), szDrive, szDir); } Usage : CString exePath; GetLaunchedDir(exePath); SetCurrentDirectory(exePath);

      1 Reply Last reply
      0
      • L Lost User

        Hi, I'm using CFileFind to search files: CListBox* pListBox = (CListBox*)GetDlgItem(IDC_FILE_LISTING); pListBox->ResetContent(); CFileFind finder; CString extension = "*.scr"; CString filepath = ""; BOOL haveFile = finder.FindFile(extension); while (haveFile) { haveFile = finder.FindNextFile(); pListBox->AddString((LPCTSTR)finder.GetFileTitle()); } I want to make it to search for a directory...for example, search c:\abc\cde\*.scr, where my program.exe file is in c:\abc....how can i do that?

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

        Let your function take a starting directory as a parameter (that you pass to FindFile). Then if you are looking at a directory in your list (IsDirectory()), call your own function with the parameter of the current directory. You will then recursively go through all of your files. A common 'add' function in your application called from your find routine will let you gather them all up. --Mark Terrano www.ensemblestudios.com (Creators of the Age of Empires series)

        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