• C++文件遍历(小工具)


    用于生成html超链接方便下载

    #include<Windows.h>
    #include<iostream>
    #include<io.h>
    #include<string>
    #include<vector>
    using namespace std;
    
    size_t FinFiles(vector<string>&files)
    {
    	files.clear();
    	char buffer[MAX_PATH] = {};
    	GetCurrentDirectoryA(MAX_PATH, buffer);
    	string path = buffer;
    	path += "\*.*";
    	_finddata_t fileinfo;
    
    	long handle = _findfirst(path.c_str(), &fileinfo);
    	if (handle == -1)
    	{
    		return -1;
    	}
    
    	do
    	{
    		printf("%s
    ", fileinfo.name);
    		files.push_back(fileinfo.name);
    	} while (!_findnext(handle, &fileinfo));
    
    	_findclose(handle);
    	handle = 0;
    	return files.size();
    }
    bool MakeHtml(vector<string>&files)
    {
    	FILE* pfile;
    	fopen_s(&pfile, "test", "wb+");
    	if (pfile == nullptr)
    	{
    		return false;
    	}
    	string s1 = "<a href="";
    	string s2 = "">";
    	string s3 = "</a><br>
    ";
    
    	for each(string curfile in files)
    	{
    		string s = s1 + curfile + s2 + curfile + s3;
    		cout << s << endl;
    		fwrite(s.c_str(), 1, s.length(), pfile);
    	}
    	fclose(pfile);
    	pfile = 0;
    	return true;
    }
    
    int main()
    {
    	vector<string>files;
    	FinFiles(files);
    	MakeHtml(files);
    	system("pause");
    	return 0;
    }
    
  • 相关阅读:
    xlrd doc
    安装Python package
    Python处理Excel(转载)
    OPENSSL简介
    sublime text2教程
    使用SQL 从表中取记录
    SQL基础
    shell脚本之grep的使用方法
    (转载)(收藏)OceanBase深度解析
    (转载)线程池的使用
  • 原文地址:https://www.cnblogs.com/biu-we/p/13261898.html
Copyright © 2020-2023  润新知