ubuntu c++ 遍历文件
来源:互联网 发布:朗读女语音软件 编辑:程序博客网 时间:2024/05/16 23:52
编译命令:g++ getSubFiles.cpp -std=c++11
/************************** * File Name: getSubFiles.cpp * Author: No One * E-mail: 1130395634@qq.com * Created Time: 2017-03-09 14:02:15**************************/#include <iostream>#include <string>#include <vector>#include <algorithm>#include <stdio.h>#include <sys/stat.h>#include <dirent.h>using namespace std;void getFiles(const char* path, vector<string>& files);int main(){ string folder = "/home/xxx/"; vector<string> files; getFiles(folder.c_str(), files); for_each(files.begin(), files.end(), [](const string &s){cout << s << endl; }); cout << endl;}void getFiles(const char* path, vector<string>& files){ const string path0 = path; DIR* pDir; struct dirent* ptr; struct stat s; lstat(path, &s); if(!S_ISDIR(s.st_mode)){ cout << "not a valid directory: " << path << endl; return; } if(!(pDir = opendir(path))){ cout << "opendir error: " << path << endl; return; } int i = 0; string subFile; while((ptr = readdir(pDir)) != 0){ subFile = ptr -> d_name; if(subFile == "." || subFile == "..") continue; subFile = path0 + subFile; cout << ++i << ": " << subFile << endl; files.push_back(subFile); } closedir(pDir);}
0 0
- ubuntu c++ 遍历文件
- linux c文件遍历
- C遍历磁盘文件
- c遍历文件
- linux c 遍历文件
- 文件遍历(C++)
- C语言文件遍历
- c/c++文件遍历
- c语言文件查找,遍历
- C、C++文件夹文件遍历
- Ubuntu 下面遍历文件夹里面的文件
- C常用类整理(1)--文件遍历
- C Windows 读取文件夹 遍历文件
- [Linux]C语言遍历文件和目录
- 采用标准c进行目录文件遍历
- [Linux]C语言遍历文件和目录
- 采用标准C进行目录文件遍历
- c遍历所有文件夹中的文件
- SSM整合--增删改查
- [译]AngularJS 1.3.0 开发者指南(二) -- 概念综述
- 《阿里聚安全2016年报》
- shiro框架实现基于redis的SessionDao
- Java隐藏手机号中间四位
- ubuntu c++ 遍历文件
- iOS播放器开发之MPMoviePlayerController
- 最大连续子数组
- RAC + MVVM 2
- In-Memory:内存优化数据的持久化和还原
- actionbar左上角的返回小图标
- mysql优化经验
- 探究Docker 1.13 存储插件和Propagated Mounts
- mybatis面试题