TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 昨天 15:13 |
---|
签到天数: 153 天 [LV.7]常住居民III
管理员
中国膜结构网www.mjgou.com
- 积分
- 2147483647
![QQ](static/image/common/qq_big.gif)
|
#include "shlwapi.h"
#pragma comment(lib,"shlwapi.lib")
#pragma comment(lib, "Version.lib ")
#include <iostream>
#include <windows.h>
#include <algorithm>
#include <time.h>
#include <io.h>
#include <fstream>
struct tagFileInfo
{
ULONG uLen;
int nCreateTime;
int nModifyTime;
string strFileName;
};
// // 获取指定目录下的所有指定格式文件,返回的列表将按照创建时间排序,最早的在最前面
bool getDirFiles(string strDir, vector<tagFileInfo>& vecFiles,string strSuffixName)
{
if (strDir.empty() || !isExistFile(strDir, true))
{
return false;
}
vecFiles.clear();
string strPath = strDir + "*.*" + strSuffixName;
// 文件信息
struct _finddata_t _fileInfo;
// 文件句柄
intptr_t hFile = _findfirst(strPath.c_str(), &_fileInfo);
if (-1 != hFile)
{
do
{
string strFileName = strDir + string(_fileInfo.name);
if (isExistFile(strFileName))
{
tagFileInfo _tagInfo;
_tagInfo.nCreateTime = static_cast<int>(_fileInfo.time_create);
_tagInfo.nModifyTime = static_cast<int>(_fileInfo.time_write);
_tagInfo.uLen = static_cast<int>(_fileInfo.size);
_tagInfo.strFileName = strFileName;
vecFiles.push_back(_tagInfo);
}
} while (0 == _findnext(hFile, &_fileInfo));
}
return true;
}
#include <vector>
using namespace std;
string m_strDir = "XXX/XX/XX";//目标目录
vector<tagFileInfo> vecFiles;
getDirFiles(m_strDir, vecFiles, "log");
|
|