ubuntu--windows获取文件路径
2016-04-01 18:55
357 查看
#include <iostream> #include <algorithm> #include <vector> #include <string> #if defined(WIN32) || defined(_WIN32) #include <io.h> #else #include <dirent.h> #endif using namespace std; static void readDirectory(const string& directoryName, vector<string>& filenames, bool addDirectoryName = true) { filenames.clear(); #if defined(WIN32) | defined(_WIN32) struct _finddata_t s_file; string str = directoryName + "\\*.*"; intptr_t h_file = _findfirst(str.c_str(), &s_file); if (h_file != static_cast<intptr_t>(-1.0)) { do { if (addDirectoryName) filenames.push_back(directoryName + "\\" + s_file.name); else filenames.push_back((string)s_file.name); } while (_findnext(h_file, &s_file) == 0); } _findclose(h_file); #else DIR* dir = opendir(directoryName.c_str()); if (dir != NULL) { struct dirent* dent; while ((dent = readdir(dir)) != NULL) { if (addDirectoryName) filenames.push_back(directoryName + "/" + string(dent->d_name)); else filenames.push_back(string(dent->d_name)); } closedir(dir); } #endif sort(filenames.begin(), filenames.end()); } int main(int argc, char* argv[]) { vector<string> images_filenames; readDirectory("./", images_filenames, false); for (int i = 0; i < images_filenames.size(); i++){ cout << images_filenames[i] << endl; } return 0; }
相关文章推荐
- 链队列的基本操作
- KVM虚拟机发送IPI的流程
- memcached和redis的区别
- 工作一直没有进步怎么办?试试PDCA法则吧!
- mysql
- 你不知道的Spring配置文件
- 3D基础--Vertex
- mac下安装tomcat
- 【Python】Python的数据分析(三)——数据文件及数据结构
- UVA 1108 - Mining Your Own Business
- 9.应用程序如何访问驱动
- 云计算:利用叶子云桌面虚拟化管理平台搭建企业的桌面云,首次使用服务器组(四)
- LeetCode-3. Longest Substring Without Repeating Characters
- (9)IText读取PDF
- JQuery之动画与特效
- HTTP抓包的实践--协议
- Android MTK 锁屏时间显示显示不全修改
- POJ题目分类
- OpenGL入门博文精选
- (8)PDFBOX读取PDF(元数据、纲要、文本、图片)