【C++】读取文件夹下所有文件名
生活随笔
收集整理的这篇文章主要介绍了
【C++】读取文件夹下所有文件名
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在文件的读取处理中,我们通常会遇到读取一个文件夹下所有文件的情形,那么若要读取该文件夹下的所有文件,我们则需要获取文件夹下的所有文件名。
下面介绍一种C++下获取一个文件夹下的所有文件名的方法,具体代码如下:
void get_file_names(std::string path_name, std::vector<std::string>& file_names) {long h_file = 0;struct _finddata_t fileinfo;std::string p;if ((h_file = _findfirst(p.assign(path_name).append("\\*").c_str(), &fileinfo)) != -1){do{if ( (fileinfo.attrib & _A_SUBDIR)){if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0){get_file_names(p.assign(path_name).append("\\").append(fileinfo.name), file_names);}}else{file_names.push_back(p.assign(path_name).append("\\").append(fileinfo.name) );}} while (_findnext(h_file, &fileinfo) == 0);}return; }
2017.05.11
《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的【C++】读取文件夹下所有文件名的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【python图像处理】两幅图像的合成一
- 下一篇: 【VC++】Visual Studio编