SimpleNotePad icon indicating copy to clipboard operation
SimpleNotePad copied to clipboard

没有遍历文件夹的功能吗?选择添加文件夹只能是根文件夹

Open Lingoing opened this issue 2 years ago • 0 comments

在对话框类->FormatConvertDlg->FormatConvertDlg.cpp中添加一个函数 std::setstd::wstring TraverseFolder(wstring path) { std::setstd::wstring filePaths; // 定义文件句柄 HANDLE hFile = INVALID_HANDLE_VALUE; // 定义文件信息 WIN32_FIND_DATA fd; // 定义文件路径 wstring strFind = path + L"\."; // 查找第一个文件 hFile = FindFirstFile(strFind.c_str(), &fd); if (INVALID_HANDLE_VALUE == hFile) { return; } // 遍历查找到的文件 while (FindNextFile(hFile, &fd)) { // 如果是文件夹,则递归 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // 忽略当前文件夹和上一级文件夹 if (wcscmp(fd.cFileName, L".") != 0 && wcscmp(fd.cFileName, L"..") != 0) { wstring str = path + L"\" + fd.cFileName; TraverseFolder(str); } } // 如果是.h或.cpp文件,则添加到vector中 else { wstring str = path + L"\" + fd.cFileName; if (str.find(L".h") != wstring::npos || str.find(L".cpp") != wstring::npos) { filePaths.insert(str); } } } // 关闭文件句柄 FindClose(hFile); return filePaths; }

Lingoing avatar Jan 06 '23 00:01 Lingoing