zoukankan      html  css  js  c++  java
  • 遍历文件夹下所有文件将文件名写到txt中(X86)

    https://www.cnblogs.com/tgyf/p/3839894.html 

    #include "io.h"
    #include <fstream>
    #include <string>
    void getFilesAll(string path, vector<string>& files) {
    	//文件句柄
    	long hFile = 0;
    	//文件信息
    	struct _finddata_t fileinfo;
    	string p;
    	if ((hFile = _findfirst(p.assign(path).append("\*").c_str(), &fileinfo)) != -1) {
    		do {
    			if ((fileinfo.attrib & _A_SUBDIR)) {
    				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
    					//files.push_back(p.assign(path).append("\").append(fileinfo.name));
    					getFilesAll(p.assign(path).append("\").append(fileinfo.name), files);
    
    				}
    
    			}
    			else {
    				files.push_back(p.assign(path).append("\").append(fileinfo.name));
    
    			}
    
    		} while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile);
    
    	}
    
    }
    int main() {
    	//void getFilesAll(string path, vector<string>& files);
    	char* filePath = "E:\bolts";
    	vector<string> files;
    	char* distAll = "E:\AllFiles.txt";
    	getFilesAll(filePath, files);
    	ofstream ofn(distAll);
    	int size = files.size();
    	ofn << size << endl;
    	for (int i = 0; i < size; i++) {
         ofn << files[i] << endl;
    			}
    		ofn.close();
    		return 0;
    }
  • 相关阅读:
    8.3学习日志
    8.2学习日志
    8.1学习日志
    Chapter 2
    未命名 1
    pugixml
    C++使用Json作为数据包装格式的通信
    项目FAQ
    xcode语法高亮插件
    【转】jsoncpp在xcode中的使用
  • 原文地址:https://www.cnblogs.com/Henry-ZHAO/p/12725183.html
Copyright © 2011-2022 走看看