void getFiles(string path, string exd, vector<string>& files) {
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string pathName, exdName;
if (0 != strcmp(exd.c_str(), ""))
{
exdName = "\\*." + exd;
}
else
{
exdName = "\\*";
}
if ((hFile = _findfirst(pathName.assign(path).append(exdName).c_str(), &fileinfo)) != -1)
{
do
{
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
files.push_back(pathName.assign(path).append("\\").append(fileinfo.name)); // 要得到绝对目录使用该语句
//如果使用
//files.push_back(fileinfo.name); // 只要得到文件名字使用该语句
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}C++找到文件夹里所有特定后缀的文件名称
最新推荐文章于 2024-01-23 23:12:37 发布
本文介绍了一个C++函数voidgetFiles,用于在指定路径下搜索符合特定扩展名的所有文件,并将这些文件的绝对路径添加到一个字符串vector中。该函数利用了_findfirst和_findnext等系统调用。
1140

被折叠的 条评论
为什么被折叠?



