//#include <io.h>
void TraverseAllFiles()
{
_finddata_t fileInfo;
string fileDir("G:\\data\\"); // 要遍历的文件夹
string fileExt("*.csv"); // 要遍历的文件扩展名
string fileFind = fileDir;
fileFind.append(fileExt);
long handle = _findfirst(fileFind.data(), &fileInfo); // 找第一个文件
if (handle == -1L)
{
return; // 没找到文件
}
int fileNumber = 0; // 记数找到多少个文件
vector<string> files; // 文件名存起来
do
{
files.push_back(fileInfo.name);
cout << "fileNumber = "<< fileNumber << " " << files[fileNumber].data() << endl;
fileNumber++;
}while (_findnext(handle, &fileInfo) == 0);
files.clear();
}
文件遍历代码(C, C++)
于 2023-12-11 10:10:53 首次发布