当前位置:网站首页>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
边栏推荐
- 高并发,你真的理解透彻了吗?
- laravel8更新之速率限制改进
- 5g/4g工业无线路由器
- 搜索引擎的日常挑战_4_外部异构资源 - 知乎
- iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- AMD Zen3首发评测:频率超5GHz,IPC提升不止19%,这次真的Yes了 - 知乎
- 5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award
- 异常+abstract
- Test requirements for MIC certification of Bluetooth 2.4G products in Japan
猜你喜欢
Astra: the future of Apache Cassandra is cloud native
Distributed consensus mechanism
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
阅读心得:FGAGT: Flow-Guided Adaptive Graph Tracking
Game mathematical derivation AC code (high precision and low precision multiplication and division comparison) + 60 code (long long) + 20 point code (Full Permutation + deep search DFS)
归纳一些比较好用的函数
laravel8更新之速率限制改进
Function periodic table filter value selectedvalue
VC6兼容性及打开文件崩溃问题解决
蓝牙2.4G产品日本MIC认证的测试要求
随机推荐
Wechat nickname Emoji expression, special expression causes the list not to be displayed, export excel error report and other problems solved!
计算机网络基本概念(五)局域网基本原理
November 07, 2020: given an array of positive integers, the sum of two numbers equals N and must exist. How to find the two numbers with the smallest multiplication?
Astra: the future of Apache Cassandra is cloud native
Visual studio 2015 unresponsive / stopped working problem resolution
Do you really understand the high concurrency?
Seven features of Python 3.9
“智能5G”引领世界,数位智能网优+5G能带来什么?
搜索引擎的日常挑战_4_外部异构资源 - 知乎
Experience the latest version of erofs on Ubuntu
Function periodic table filter value selectedvalue
Littlest jupyterhub| 02 using nbgitpuller to distribute shared files
PX4添加新的应用
Windows subsystem Ubuntu installation
What details does C + + improve on the basis of C
ASP.NET MVC下基于异常处理的完整解决方案
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
Game mathematical derivation AC code (high precision and low precision multiplication and division comparison) + 60 code (long long) + 20 point code (Full Permutation + deep search DFS)
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
What is the difference between vivoy73s and vivoy70s