您的位置:首页 > 编程语言 > C语言/C++

遍历文件夹下某种类型文件名(C++)

2016-04-26 22:04 288 查看
在文件夹下,查找某后缀的文件:

vector<string> findfileinfolder(string fileFolderPath, string fileExtension)//文件路径和后缀名
{
string fileFolder = fileFolderPath + "\\*." + fileExtension;
vector<string> file;

char fileName[2000];

struct _finddata_t fileInfo;

long findResult = _findfirst(fileFolder.c_str(), &fileInfo);
if (findResult == -1)
{
_findclose(findResult);
return file;
}
bool flag = 0;

do
{
sprintf(fileName, "%s\\%s", fileFolderPath.c_str(), fileInfo.name);

if (fileInfo.attrib == _A_ARCH)
{
file.push_back(fileName);
//Mat frame = imread(fileName, 1);
//imshow("1", frame);
}

} while (!_findnext(findResult, &fileInfo));

_findclose(findResult);

return file;
}

……
vector<string> jpg = findfileinfolder("D:\\图片","jpg");
……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  遍历 文件