当前位置:网站首页>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
边栏推荐
- IOS upload app store error: this action cannot be completed - 22421 solution
- Python loop distinction (while loop and for loop)
- Qt混合Python开发技术:Python介绍、混合过程和Demo
- Codeforce算法题 | 你能想出解法,让你的基友少氪金吗?
- iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
- 蓝牙2.4G产品日本MIC认证的测试要求
- [original] about the abnormal situation of high version poi autosizecolumn method
- IOS learning note 2 [problems and solutions encountered during the installation and use of cocopods] [update 20160725]
- sed之查找替换
- 面部识别:攻击类型和反欺骗技术
猜你喜欢
Which is more worth starting with the difference between vivos7e and vivos7
vivoY73s和vivoY70s的区别 vivoY73s和vivoY70s哪个值得入手
技术人员该如何接手一个复杂的系统?
2020-11-05
C++在C的基础上改进了哪些细节
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)
Cloud alibabab notes come out, the whole network detailed explanation only this one hand is slow
More than 50 object detection datasets from different industries
ulab 1.0.0发布
来自不同行业领域的50多个对象检测数据集
随机推荐
ubuntu实时显示cpu、内存占用率
异常+abstract
Unparseable date: 'mon Aug 15 11:24:39 CST 2016', time format conversion exception
技术人员该如何接手一个复杂的系统?
print( 'Hello,NumPy!' )
What details does C + + improve on the basis of C
游戏优化性能杂谈(十一) - 知乎
Macquarie Bank drives digital transformation with datastex enterprise (DSE)
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
计算机网络基本概念(五)局域网基本原理
Insight -- the application of sanet in arbitrary style transfer
Littlest JupyterHub| 02 使用nbgitpuller分发共享文件
VC6 compatibility and open file crash resolution
Do you really understand the high concurrency?
Astra: Apache Cassandra的未来是云原生
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
laravel8更新之速率限制改进
分布式共识机制
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
Blazor 准备好为企业服务了吗?