You are here:

C++/Drectory Search Handler


Dear Sir,

I am using the following:-(Uses the OS Opening Directory Handler)

int  CTMConverterUIDlg::getFilesNumInFolder(string& dataFilesFolder)
  string fileName;
  int filesNum=0;
WIN32_FIND_DATA fileData;
   HANDLE searchHandle = NULL;
  //std::string folderName(char*);
  //string l_sLowerCase("");
  string sFolderName(dataFilesFolder);
  if (searchHandle == NULL)
       searchHandle = FindFirstFile(sFolderName.c_str(), &fileData);
  if(searchHandle == INVALID_HANDLE_VALUE)
     MessageBox("Error - searching files","Error",MB_OK);
     fileName = "";      
  //first file
  fileName = fileData.cFileName;
  if( (strcmp((const char*)fileName.c_str() , (const char*)ISOLATED_LOG_FILE ) == 0 ) &&  searchHandle != INVALID_HANDLE_VALUE  /*&& FindNextFile(searchHandle, &fileData)*/ ){
     //fileName = dataFilesFolder + "\\" + fileName; //sending the whole file name path
  else {
  bool lastFile = false;

  while ((searchHandle != INVALID_HANDLE_VALUE)&& FindNextFile(searchHandle, &fileData))
     fileName = fileData.cFileName;
     fileName = dataFilesFolder + "\\" + fileName;
     string logName = dataFilesFolder + LOG_FILE_NAME;
     if(strcmp((const char*)fileName.c_str() , (const char*)logName.c_str() ) !=0){//For not testing itself , the LogFile


   searchHandle = NULL;

  return filesNum;


Followup To
Question -
No... it does not help me so much.
If you can give me example or an implementation that does that.

Followup To
Question -

I am Eng.Wael Slaman. Hope that you can help me and supply me with good or maybe excellent C++ (MFC)class that enables my application to brows the operating System (Win XP) directory and then select the files that I want from a folder.

In other words!  I have GUI (MFC) that was developed upon  C++ application. This GUI should give me the opportunity to BROWSE the OS Directory and select the files that I want.

I have one that enables me to select whole folder and not specific files that I want from a folder.

I will be so happy if you can provide me as soon as possible.

Answer -
Wael , Thank you for your question.

I believe that the CFileDialog class will do what you want. If not, let me know and I will help you further.

David Spector

Answer -
Wael, I am sorry that CFileDialog does not work for you.

Describe the problem with using CFileDialog and I will see if I can help further.

Bear in mind that allexperts is a free service, so any help you can give me in describing your problem carefully and completely will be appreciated.


Wael, I regret that I am unable to take the time to study your source code due to the volume of questions received. If you can create a shorter example, a tiny test case, or a more specific question, I will be pleased to help you.

Your description "to BROWSE the OS Directory and select the files that I want" is not clear enough for me to give you a useful answer.



All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.