gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Windows下C++遍历文件夹下所有文件,然后使用b tree存储结果
- User
Windows下C++遍历文件夹下所有文件,然后使用b tree存储结果
- Assistant
以下是一个Windows下使用C++遍历文件夹并使用b树存储结果的示例代码:
c++#include <iostream> #include <string> #include <vector> #include <Windows.h> #include "btree/btree_map.h" using namespace std; // 遍历文件夹 void traverseFolder(const string& folderPath, btree::btree_map<string, string>& files) { // 构建查询条件 string search_path = folderPath + "/*.*"; WIN32_FIND_DATAA fd; HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &fd); if (hFind != INVALID_HANDLE_VALUE) { do { // 判断是否为文件夹 if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // 将文件路径存储到 b 树中 files.insert({fd.cFileName, folderPath}); } } while (::FindNextFileA(hFind, &fd)); ::FindClose(hFind); } } int main() { // 定义文件夹路径 string folderPath = "C:\\Users\\username\\Desktop\\test"; // 定义 b 树 btree::btree_map<string, string> files; // 遍历文件夹并存储结果到 b 树中 traverseFolder(folderPath, files); // 遍历 b 树输出结果 for (const auto& file : files) { cout << file.first << " " << file.second << endl; } return 0; } - User
分割目录路径,节点子存放文件或文件夹名
- Assistant
以下是一个分割目录路径,节点子存放文件或文件夹名的示例代码:
c++