heres my actual code for find\search a folder:
string FindDirectory(std::string FindDirectoryName[2], std::string StartDirectory="C:")
{
WIN32_FIND_DATA file={0};
string str=StartDirectory+ "\\*";
HANDLE search_handle = FindFirstFile(str.c_str(), &file);
static bool 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]=="")
{
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;
}
//use it:
string File[]={"x86_64-7.2.0-win32-seh-rt_v5-rev1","mingw64"};
string FileName1=FindDirectory(File);
MessageBox(NULL,FileName1.c_str(),"hey", MB_OK);
these code works, but sometimes can get 2 or more minutes... is there another faster way?