#pragma once #include #include #include #include #include "PublicFunc.h" class FileTools { public: static std::vector getFiles(std::string path) { std::vector files; getFiles(path, files); return files; } static void write_log(std::string log) { TCHAR szIniFile[MAX_PATH] = { 0 }; SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE); _tcscat(szIniFile, HUAGAO_SCAN); _tcscat(szIniFile, TWAIN_INIPATH); _tcscat(szIniFile, TEXT("\\")); _tcscat(szIniFile, TWAIN_LOG_NAME); std::string savepath = TCHAR2STRING(szIniFile); write_log(savepath, log); } static void write_log(std::string filename, std::string log) { //std::string savepath; //std::string str = "D:"; //savepath = str+"\\"+filename; std::ofstream ofs(filename, std::ios::app); time_t timp; tm* p; time(&timp); p=localtime(&timp); ofs << p->tm_year+1900 << "/" << p->tm_mon+1 << "/" << p->tm_mday << " " << p->tm_hour << ":" << p->tm_min << ":" << p->tm_sec << " "<setName(LOG4CPLUS_TEXT("file")); // log4cplus::tstring pattern = LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S,%Q} [%t] %-5p %c - %m [%l]%n"); // rf->setLayout(std::unique_ptr(new log4cplus::PatternLayout(pattern))); // log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("hglog")); // logger.setLogLevel(log4cplus::INFO_LOG_LEVEL); // logger.addAppender(rf); // LOG4CPLUS_WARN(logger, log.c_str()); // logger.removeAllAppenders(); //} private: static void getFiles(std::string path, std::vector& files) { //文件句柄 long hFile = 0; //文件信息 struct _finddata_t fileinfo; std::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) getFiles(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); } } };