void findFile(const std::wstring &directory, wstring inputSearch)
{ // , char *currDrives){ //function for algorithm to search your computer to find what you want to load
//wcout << directory << endl;
//cout << "In" << endl;
wstring search = inputSearch;
std::wstring tmp = directory + L"\\*";
size_t found;
WIN32_FIND_DATAW file;
HANDLE search_handle = FindFirstFileW(tmp.c_str(), &file);
if (search_handle != INVALID_HANDLE_VALUE)
{
std::vector<std::wstring> directories;
do
{
found = tmp.find_last_of(L"/\\");
if (tmp.substr(found + 1) == inputSearch) {
cout << "Found File" << endl;
continueSearching = false;
foundFilePath = tmp;
}
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((!lstrcmpW(file.cFileName, L".")) || (!lstrcmpW(file.cFileName, L".."))) {
continue;
}
}
tmp = directory + L"\\" + std::wstring(file.cFileName);
bruteForceComp++;
//std::wcout << tmp << std::endl;
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
directories.push_back(tmp);
} while (FindNextFileW(search_handle, &file) && continueSearching == true);
FindClose(search_handle);
for (std::vector<std::wstring>::iterator iter = directories.begin(), end = directories.end(); iter != end; ++iter) {
findFile(*iter, inputSearch);
}
}
}
我们有这个功能可以搜索某个驱动器中的所有子目录。我们将其与用户输入的搜索词进行比较。 (驱动器和搜索项是传递给函数的两个参数)我们很好地找到.exe文件和一堆其他文件,但是当我们尝试找到.docx或.txt文件时,它们不会出现。任何帮助找到原因将不胜感激。我们有点难过。
谢谢!
findFilePath顺便说一下是一个静态的wstring。这是我们将匹配路径存储到搜索词的位置。搜索词也以word.exe或yay.docx的形式输入。