文件自动拆分

将一个文件中同一编号的数据拆分,分别放到新建的文件夹中去。
文件自动拆分
文章图片
文件自动拆分
文章图片
文件自动拆分
文章图片

5 #include 6 #include 7 #include 8 #include 9 #include 10 #include //创建文件夹头文件 11 #include//获取时间头文件 12 using namespace std; 13 14 15 void getFiles( string path, vector& files, vector &ownname) 16 { 17/*files存储文件的路径及名称(eg.C:\Users\WUQP\Desktop\test_devided\data1.txt) 18ownname只存储文件的名称(eg.data1.txt)*/ 19 20//文件句柄 21longhFile=0; 22//文件信息 23struct _finddata_t fileinfo; 24string p; 25if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) !=-1) 26{ 27do 28{ 29//如果是目录,迭代之 30//如果不是,加入列表 31if((fileinfo.attrib &_A_SUBDIR)) 32{/* 33if(strcmp(fileinfo.name,".") != 0&&strcmp(fileinfo.name,"..") != 0) 34getFiles( p.assign(path).append("\\").append(fileinfo.name), files, ownname ); */ 35} 36else 37{ 38files.push_back(p.assign(path).append("\\").append(fileinfo.name) ); 39ownname.push_back(fileinfo.name); 40} 41}while(_findnext(hFile, &fileinfo)== 0); 42_findclose(hFile); 43} 44 } 45 46 int main() 47 { 48 49clock_t start_time=clock(); //开始时间 50 51int detector_seq; 52int sequence; 53int arrive_time; 54 55char * filePath = "C:\\Users\\WUQP\\Desktop\\test_devided"; 56char * addfilePath = "\\processed_data"; 57char processedfilePath[100]; 58strcpy_s(processedfilePath, filePath); 59strcat_s(processedfilePath, addfilePath); 60cout << processedfilePath << endl; 61_mkdir(processedfilePath); 62 63vector files; 64vector ownname; 65 66//获取该路径下的所有文件 67getFiles(filePath, files, ownname); 68int size = files.size(); 69for (int i = 0; i < size; i++) 70{ 71cout<> detector_seq >> sequence >> arrive_time) 81{ 82if(detector_seq == 0) 83{ 84++num_receiver_times; 85} 86else break; 87} 88} 89in_File.close(); 90 91//根据事件数目动态分开各事件的数据 92cout << "the sources of this file is " << num_receiver_times << endl; 93vector* p = new vector[num_receiver_times]; 94ifstream in_File_(files[i].c_str()); 95if (in_File_.is_open()) 96{ 97while (getline(in_File_, in_str)) 98{ 99for (int j=0; j::iterator iter = p[k].begin(); iter!= p[k].end(); iter++) 119{ 120cout << flag++ << ":" << *iter << endl; 121outfile << *iter << endl; 122} 123outfile.close(); 124} 125} 126 127clock_t end_time=clock(); //结束时间 128 129cout<< "Running time is: " 130(end_time - start_time)/CLOCKS_PER_SEC 131<<"(s)"<

【文件自动拆分】转载于:https://www.cnblogs.com/wqpkita/p/6849253.html

    推荐阅读