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