当前位置:网站首页>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
边栏推荐
- 解决RabbitMQ消息丢失与重复消费问题
- Deeplight Technology Bluetooth protocol SRRC certification services
- 成功解决An error ocurred while starting the kernel
- That's what software testing is all about?!
- 2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
- C expression tree (1)
- [original] about the abnormal situation of high version poi autosizecolumn method
- Game optimization performance (11) - Zhihu
- nvm
- Introduction to ucgui
猜你喜欢

Macquarie Bank drives digital transformation with datastex enterprise (DSE)

Deeplight Technology Bluetooth protocol SRRC certification services

FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem

Do you really understand the high concurrency?

Adobe Prelude /Pl 2020软件安装包(附安装教程)

【原创】关于高版本poi autoSizeColumn方法异常的情况

ts流中的pcr与pts计算与逆运算

Experience the latest version of erofs on Ubuntu

i5 1135g7和i5 1035g1参数对比区别大吗? 哪个好

OSChina 周日乱弹 —— 之前呢,我一直以为自己是个……
随机推荐
计算机网络基本概念(五)局域网基本原理
Julia 是如何风靡起来的?
How did Julia become popular?
面部识别:攻击类型和反欺骗技术
That's what software testing is all about?!
ubuntu实时显示cpu、内存占用率
Oschina plays on Sunday - before that, I always thought I was a
Codeforce算法题 | 你能想出解法,让你的基友少氪金吗?
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
C expression tree (1)
PX4添加新的应用
Visual studio 2015 unresponsive / stopped working problem resolution
异常+abstract
1.深入Istio:Sidecar自动注入如何实现的?
Face recognition: attack types and anti spoofing techniques
接口
模板链表类学习
Introduction to ucgui
print( 'Hello,NumPy!' )
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统