Apart from this I don't see why it would go inifinite. It may go a long time depending on the number of files within the directory. I suggest that you make your own directory not 'C:' to start from.
string FindDirectory(std::string FindDirectoryName[2], std::string StartDirectory="C:")
{
WIN32_FIND_DATA file={0};
string str=StartDirectory+ "\\*"; //we must add the backslash with asterisc
HANDLE search_handle = FindFirstFile(str.c_str(), &file);
staticbool blnFindDirectoryName=false;
static string strFolderName ="";
//testing if the folder is valid:
if (search_handle != INVALID_HANDLE_VALUE)
{
do
{
//if the folder was founded, then break the loop:
if(strFolderName!="")
break;
//for avoid files names and the folders "." and "..":
if ((file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(file.cFileName, "..") && strcmp(file.cFileName, "."))
{
//cout <<StartDirectory + "\\" + file.cFileName << endl;
//testing if the folder was found
//and add it on static strFolderName
if(string(file.cFileName)==FindDirectoryName[0] && blnFindDirectoryName==false)
{
if(FindDirectoryName[1]=="")
{
//the entire folder path must be startdirectory more backslash and then forlder name
strFolderName = StartDirectory+ "\\" + file.cFileName;
break;
}
else
blnFindDirectoryName=true;
}
if(string(file.cFileName)==FindDirectoryName[1] && blnFindDirectoryName==true)
{
//MessageBox(NULL, string(StartDirectory+ "\\" + file.cFileName).c_str(), "found it", MB_OK);
strFolderName = StartDirectory+ "\\" + file.cFileName;
break;
}
else
{
//or continue searching:
FindDirectory(FindDirectoryName,StartDirectory + "\\" + file.cFileName);
}
}
} while (FindNextFile(search_handle, &file) && search_handle!=NULL);
//destroy the search_handle:
FindClose(search_handle);
}
//return the search folder full path:
return strFolderName;
}
//testing:
string str2[2]={"mingw64","bin"};//2 strings(folder and subfolder) for have sure that found the right program folder
cout << FindDirectory(str2);
now i can search a program more easy ;)
thank you so much for all.. thank you