I wrote a simple recursive file search by mask. With English characters, everything works fine, but as soon as the program meets Russian, it sends garbage to the buffer and the function crashes. I tried to take the code from this site (from a similar question), but it also does not work with Russian characters. Code example:
typedef std::basic_string<TCHAR> StdString; function to search for files in the current folder
void ScanFolder(const StdString & folder, const StdString & mask) { WIN32_FIND_DATA find_data; HANDLE find_handle = FindFirstFile((folder + mask).c_str(), &find_data); if (INVALID_HANDLE_VALUE == find_handle) { return; } else { do { cout << folder << find_data.cFileName << endl; } while (FindNextFile(find_handle, &find_data)); FindClose(find_handle); } and recursive function for searching folders and calling the first function
void FindFileRecursive(StdString start_path, const StdString & mask) { start_path = rtrim(start_path) + _T("\\"); ScanFolder(start_path, mask); WIN32_FIND_DATA folder_data; HANDLE folder_find = FindFirstFileEx ( (start_path + _T("*")).c_str() , FindExInfoStandard , &folder_data , FindExSearchLimitToDirectories // поиск папок , NULL , FIND_FIRST_EX_LARGE_FETCH ); if (INVALID_HANDLE_VALUE == folder_find) { return; } else { do { if (FILE_ATTRIBUTE_DIRECTORY & folder_data.dwFileAttributes) { if (strcmp(folder_data.cFileName, ".") && strcmp(folder_data.cFileName, "..")) { FindFileRecursive( start_path + folder_data.cFileName, mask) } } } while (FindNextFile(folder_find, &folder_data)); FindClose(folder_find); } } Error due to the fact that negative values (Russian letters) are passed to the function. How to pass a string as an argument in this case?
strcmptry using_tcscmp. And in general, do not mix C and C ++. - Alexander Petrov