82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <Windows.h>
|
|
#include <io.h>
|
|
#include <fstream>
|
|
#include <mutex>
|
|
|
|
class FileTools
|
|
{
|
|
public:
|
|
|
|
|
|
static std::vector<std::string> getFiles(std::string path)
|
|
{
|
|
std::vector<std::string> files;
|
|
getFiles(path, files);
|
|
return files;
|
|
}
|
|
|
|
static void write_log(std::string filename, std::string log)
|
|
{
|
|
//#ifdef DEBUG
|
|
char deskpatrh[255];
|
|
std::string savepath;
|
|
SHGetSpecialFolderPath(0, deskpatrh, CSIDL_DESKTOPDIRECTORY, 0);
|
|
std::string str(deskpatrh);
|
|
savepath = str + "\\" + filename;
|
|
;
|
|
std::ofstream ofs(savepath, std::ios::app);
|
|
|
|
SYSTEMTIME sys;
|
|
GetLocalTime(&sys);
|
|
ofs << sys.wYear << "/" << sys.wMonth << "/" << sys.wDay << " " << sys.wHour << ":" << sys.wMinute << ":" << sys.wSecond << ":" << sys.wMilliseconds << " " << log << std::endl;
|
|
//#else
|
|
|
|
|
|
//#endif
|
|
}
|
|
|
|
private:
|
|
static void getFiles(std::string path, std::vector<std::string>& 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);
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
class StopWatch
|
|
{
|
|
public:
|
|
StopWatch() { valEnd = valStart = clock(); }
|
|
void start() { valStart = clock(); }
|
|
void stop() { valEnd =clock(); }
|
|
void reset() { valStart = clock(); }
|
|
double time_run() { return (double)(valEnd - valStart)/CLOCKS_PER_SEC; }
|
|
|
|
private:
|
|
clock_t valStart;
|
|
clock_t valEnd;
|
|
}; |