标签:
上次matlab也是这样。dir读写文件没关闭,循环读。调了半天。
这次又来!原来写了44行,应改写在42行。再一次强调,看代码要十分耐心。
1 vector< vector<string> > readFileList::GetFileNameFromVideoDir() 2 { 3 vector<string> vFileDirList_out; 4 vector< vector<string> > vFileDirList_all; 5 DIR *dir; 6 struct dirent *ptr; 7 //get outer fold names 8 dir = opendir(root_path.c_str()); 9 LOG(INFO)<<"wanggcong!!!******************************"; 10 while( (ptr = readdir(dir)) != NULL) 11 { 12 string filename = string(ptr->d_name); 13 if (filename[0] == ‘.‘){ 14 continue; 15 } 16 string path = root_path + string("/") + filename; 17 vFileDirList_out.push_back(path); 18 } 19 closedir(dir); 20 //according to outer folds names, we can get the videos from 21 //every fold one by one 22 LOG(INFO)<<"wanggcong!!!*******************************"; 23 for (int i=0; i < vFileDirList_out.size(); ++i) 24 { 25 vector<string> vFileDirList_in; 26 dir = opendir(vFileDirList_out[i].c_str()); 27 28 LOG(INFO)<<"wanggcong:name:"<<vFileDirList_out[i]; 29 LOG(INFO)<<"wanggcong:size:"<<vFileDirList_out.size(); 30 LOG(INFO)<<"wanggcong:dir:"<<dir; 31 LOG(INFO)<<"wanggcong:ptr:"<<ptr; 32 while( (ptr = readdir(dir)) != NULL) 33 { 34 string filename = string(ptr->d_name); 35 if (filename[0] == ‘.‘){ 36 continue; 37 } 38 string path = vFileDirList_out[i] + string("/") + filename; 39 vFileDirList_in.push_back(path); 40 } 41 vFileDirList_all.push_back(vFileDirList_in); 42 closedir(dir); 43 } 44 // closedir(dir); 45 LOG(INFO)<<"wanggcong!!!*******************************"; 46 47 return vFileDirList_all; 48 }
标签:
原文地址:http://www.cnblogs.com/Wanggcong/p/5366990.html