当前位置:网站首页>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
边栏推荐
- More than 50 object detection datasets from different industries
- vivoY73s和vivoY70s的区别 vivoY73s和vivoY70s哪个值得入手
- 成功解决An error ocurred while starting the kernel
- Cloud Alibabab笔记问世,全网详解仅此一份手慢无
- Visual studio 2015 unresponsive / stopped working problem resolution
- 2020-11-05
- 来自不同行业领域的50多个对象检测数据集
- sed之查找替换
- Deeplight Technology Bluetooth protocol SRRC certification services
- Search and replace of sed
猜你喜欢
M-end software product design considerations - Zhihu
Astra: the future of Apache Cassandra is cloud native
0.计算机简史
SQL Server 2008R2 18456错误解决方案
More than 50 object detection datasets from different industries
Is there a big difference between i5 1135g7 and i51035g1? Which is better?
解决Safari浏览器下载文件文件名称乱码的问题
Sum up some useful functions
VC6兼容性及打开文件崩溃问题解决
计算机网络基本概念(五)局域网基本原理
随机推荐
Wechat nickname Emoji expression, special expression causes the list not to be displayed, export excel error report and other problems solved!
Application of bidirectional LSTM in outlier detection of time series
Qt混合Python开发技术:Python介绍、混合过程和Demo
[summary series] technical system of Internet server: high performance database index
Mate 40 series launch with Huawei sports health service to bring healthy digital life
Solve Safari browser download file name garbled problem
Improvement of rate limit for laravel8 update
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
PCR and PTS calculation and inverse operation in TS stream
鼠标变小手
M-end software product design considerations - Zhihu
游戏优化性能杂谈(十一) - 知乎
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
How does spotify drive data-driven decision making?
nvm
Deeplight Technology Bluetooth protocol SRRC certification services
1.深入Istio:Sidecar自动注入如何实现的?
Tiktok live monitoring Api: random recommendation
ts流中的pcr与pts计算与逆运算
How did Julia become popular?