C++17 filesystem, Regex traversal Directory

Source: Internet
Author: User

C++17 FS is still pretty good.

#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 traversal Directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.