windows C++ 遍历目录,获取文件名和文件路径

来源:互联网 发布:2017淘宝刷不了单 编辑:程序博客网 时间:2024/06/05 11:43
void  GetFiles(string path, vector<string> &filesPath,  vector<string>& filesName){WIN32_FIND_DATAA ffd;memset(&ffd, 0, sizeof(ffd));path.append("\\*");HANDLE hFind = FindFirstFileA(path.c_str(), &ffd);do {if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName, ".."))continue;string newPath;newPath = path.append("\\").append(ffd.cFileName);GetFiles(newPath, filesPath, filesName);}else{char filePath[256] = { 0 };sprintf_s(filePath, "%s/%s", path.c_str(), ffd.cFileName);filesName.push_back(ffd.cFileName);filesPath.push_back(filePath);}} while (FindNextFileA(hFind, &ffd) != 0);FindClose(hFind);}


原创粉丝点击