• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Tricker_5

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

C++获取文件下的所有文件

转自博客 https://blog.csdn.net/cxf7394373/article/details/7195661

用自己命名风格改了改,便于后续copy,需要头文件 <io.h>

void getFileNames(string path, vector<string>& v_file_name) {
    //文件句柄
    long h_file = 0;
    //文件信息
    struct _finddata_t file_info;
    string p;
    if ((h_file = _findfirst(p.assign(path).append("\\*").c_str(), &file_info)) != -1) {
        do {
            //如果是目录,迭代之
            //如果不是,加入列表
            if ((file_info.attrib & _A_SUBDIR)) {
                //暂时不晓得为啥在文件夹目录下name属性有".",经调试确实会有
                if (strcmp(file_info.name, ".") != 0 && strcmp(file_info.name, "..") != 0) 
                    getFileNames(p.assign(path).append("\\").append(file_info.name), v_file_name);
            }
            else {
                v_file_name.push_back(p.assign(path).append("\\").append(file_info.name));
            }
        } while (_findnext(h_file, &file_info) == 0);
        _findclose(h_file);
    }
}

 

posted on 2020-10-01 00:41  Tricker_5  阅读(103)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3