首页 > 编程语言 > 详细

c++17 filesystem, regex 遍历目录

时间:2018-09-04 00:01:52      阅读:522      评论:0      收藏:0      [点我收藏+]

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去掉扩展名
    }
}

c++17 filesystem, regex 遍历目录

原文:https://www.cnblogs.com/scotth/p/9581734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!