c++ 读取文件夹下面的所有文件(windows l;inux通用)

/********************************************************************************************************
*
* 函 数 名:int seaHeightPath
* 函数说明:
* 根据日期范围查找文件路径
* 入参说明:
* file_path 文件所在路径
* srart_time 起始时间
* end_time 结束时间
* filenames 输出文件名数组
* 参数说明:
* Return code: <0 Error, ==0 Success, >0 Timeout
* 编写日期:20220516
*
********************************************************************************************************/

include

include

include <stdio.h>

include <stdlib.h>

include <string.h>

include <time.h>

include

int getFileNames(const string & file_path, vector<string>& nameVector)
{
    DIR *pDir;
    struct dirent* ptr;
    if (!(pDir = opendir(file_path.c_str())))
    {
        cout << "没找到文件" << endl;
        return -1;
    }
    while ((ptr = readdir(pDir)) != 0)
    {
        if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0)
            nameVector.push_back(ptr->d_name);
    }
    closedir(pDir);
    return 0;
}
posted @   xiaomaixiaomai  阅读(541)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示