【ok】获取文件夹下所有文件(包括文件夹)

来源:互联网 发布:在线教育直播平台源码 编辑:程序博客网 时间:2024/05/17 05:54

留一份网上存档,以后用得到!


#include <iostream>#include <string>#include <io.h>#include <vector>using namespace std;bool getDirFilesPath( string folderPath, vector<string>& files);int main(){string path;vector<string> files;cin >> path;getDirFilesPath(path,files);for (int i=0;i<files.size();i++){cout<<files.at(i)<<"\n";}system("pause");return 0;}//获得某文件夹下的所有文件的绝对路径bool getDirFilesPath( string folderPath, vector<string>& files){//文件句柄long hFile   =   0;//文件信息struct _finddata_t fileinfo;string p;if((hFile = _findfirst(p.assign(folderPath).append("\\*").c_str(),&fileinfo)) !=  -1){do{//如果是目录,继续if((fileinfo.attrib &  _A_SUBDIR)){if(strcmp(fileinfo.name,".") != 0  &&  strcmp(fileinfo.name,"..") != 0){//cout<<"文件夹\n";files.push_back( fileinfo.name );}}else{files.push_back( fileinfo.name );}}while(_findnext(hFile, &fileinfo)  == 0);_findclose(hFile);}else{return false;}return true;}



0 0
原创粉丝点击