当前位置:网站首页>VC++指定目录下文件按时间排序输出
VC++指定目录下文件按时间排序输出
2020-11-08 09:40:00 【osc_4punxmqt】
功能: 获取某一指定目录下的所有文件,然后按时间排序保存,一般用于界面展示,或者文件列表排序功能...
//排序
void CSubCameraControlDlg::FileArraySortbySystemTime(CStringArray& _arr)
{
int len = _arr.GetCount();
for(int i=0; i<len-1; i++)
{
int min=i;
for(int j=i+1; j<len; j++)
{
CString strtime1=GetFileLastModifyTime(_arr[min]);
CString strtime2=GetFileLastModifyTime(_arr[j]);
if(lstrcmpi(strtime1,strtime2)>0)
{
min=j;
}
}
CString t=_arr[min];
_arr[min]=_arr[i];
_arr[i]=t;
}
}
//获取时间
CString GetFileLastModifyTime(LPCTSTR strPath)
{
if (!::PathFileExists(strPath))
{
return _T("");
}
WIN32_FIND_DATA ffd ;
HANDLE hFind = FindFirstFile(strPath,&ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
return _T("");
}
SYSTEMTIME st = {0};
FILETIME LocalFileTimel;
FileTimeToLocalFileTime(&ffd.ftLastWriteTime, &LocalFileTimel);
FileTimeToSystemTime(&LocalFileTimel, &st);
CString strFormat;
strFormat.Format(_T("%04d-%02d-%02d %02d:%02d:%02d.%03d"),st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
FindClose(hFind);
return strFormat;
}
//查找目录下的文件
void CSubCameraControlDlg::FindDirFile(CString strdir, CStringArray& _arr)
{
TCHAR szPath[MAX_PATH] = {0};
::GetModuleFileName(NULL, szPath, MAX_PATH);
::PathRemoveFileSpec(szPath);
CString strffmpegPath;
::PathCombine(strffmpegPath.GetBufferSetLength(MAX_PATH), szPath, strdir);
// CString filepath = _T("/path/to/folder/");
CString filename = _T("");
CString fullname = _T("");
CFileFind find;
BOOL IsFind = find.FindFile(strffmpegPath + _T("/*.*"));
while (IsFind)
{
IsFind = find.FindNextFile();
if (find.IsDots())
{
continue;
}
else
{
filename = find.GetFileName();
fullname = strffmpegPath + filename;
_arr.Add(fullname);
}
}
}
版权声明
本文为[osc_4punxmqt]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4365009/blog/4707944
边栏推荐
- swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
- More than 50 object detection datasets from different industries
- 蓝牙2.4G产品日本MIC认证的测试要求
- Simple use of future in Scala
- python学习 day1——基础学习
- 5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award
- IOS upload app store error: this action cannot be completed - 22421 solution
- 个人短网址生成平台 自定义域名、开启防红、统计访问量
- c# 表达式树(一)
- C expression tree (1)
猜你喜欢

5G+AR出圈,中国移动咪咕成第33届中国电影金鸡奖全程战略合作伙伴

PCR and PTS calculation and inverse operation in TS stream

swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案

Face recognition: attack types and anti spoofing techniques

That's what software testing is all about?!

Macquarie Bank drives digital transformation with datastex enterprise (DSE)

C++在C的基础上改进了哪些细节

PCIe 枚举过程

python_scrapy_房天下

2020-11-05
随机推荐
Swiper window width changes, page width height changes lead to automatic sliding solution
麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
ts流中的pcr与pts计算与逆运算
Astra: the future of Apache Cassandra is cloud native
Mouse small hand
Visual Studio 2015 未响应/已停止工作的问题解决
M-end software product design considerations - Zhihu
阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking
Rust:命令行参数与环境变量操作
shiyou的数值分析作业
Adobe Prelude /Pl 2020软件安装包(附安装教程)
Simple use of future in Scala
Qt混合Python开发技术:Python介绍、混合过程和Demo
M 端软件产品设计思虑札记 - 知乎
python 循环区分(while循环和for循环)
2020-11-05
Oops, the system is under attack again
Summary of knowledge points of Jingtao project
哔哩哔哩常用api
“智能5G”引领世界,数位智能网优+5G能带来什么?