我是靠谱客的博主 糊涂秀发,这篇文章主要介绍linux c++ 查找指定路径下的特定类型文件,现在分享给大家,希望可以做个参考。

#include <iostream>
#include <string>
#include <regex>
#include <dirent.h>

using namespace std;

int DirProcess(string dirPath)
{
    DIR *pDir;
    struct dirent *pDirent;

    pDir = opendir(dirPath.c_str());
    if (pDir == NULL)
    {
        cout << dirPath << " is not existed" << endl;
        return -1;
    }

    while ((pDirent = readdir(pDir)) != NULL)
    {
        string s(pDirent->d_name);
        bool res = regex_match(s, regex("..xml"));
        if(res)
        {
            std::cout<<s<<std::endl;
        }
    }

    closedir(pDir);

    return 0;
}

int main()
{
    DirProcess("./data");
}

当前data目录下的文件:

运行结果:

 

 

最后

以上就是糊涂秀发最近收集整理的关于linux c++ 查找指定路径下的特定类型文件的全部内容,更多相关linux内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(130)

评论列表共有 0 条评论

立即
投稿
返回
顶部