阅读背景:

c++17 filesystem, regex 遍历目录

来源:互联网 

c++17 FS 还是挺好用的


#include<filesystem>
#include<regex>  //正则表达式

namespace fs = std::experimental::filesystem;


int main()
{
    string strPath = "D:\pic\new";
    regex fileSuffix("(.*)(.jpg)");// *.jpg, *.png  

    //regex fileSuffix("(.*).(.jpg)"); 也行
    //regex fileSuffix(".*z.*\.(jpg|png)");//包含字母z的所有jpg或png图片

    for (auto&DirectoryIter : fs::directory_iterator(strPath))
    {
        auto filepath = DirectoryIter.path();
        auto filename = filepath.filename();
    if (std::regex_match(filename.string(), fileSuffix))
    {
        vecFilePath.push_back(filepath.string());
        cout << filepath << endl;
    }
    //replace_extension替换扩展名
    //stem去掉扩展名
    }
}
#include<filesystem>
#include



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: