how find a folder name?
i have these function for get the entire folder name:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
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;
}
|
but these code it's slow. is there another way for do it more faster?
it takes more 2 minutes for find it
Last edited on
Topic archived. No new replies allowed.