当前位置:网站首页>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
边栏推荐
- 成功解决An error ocurred while starting the kernel
- 高并发,你真的理解透彻了吗?
- 游戏优化性能杂谈(十一) - 知乎
- Oschina plays on Sunday - before that, I always thought I was a
- Fgagt: flow guided adaptive graph tracking
- [summary series] technical system of Internet server: high performance database index
- 麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
- How does spotify drive data-driven decision making?
- scala 中 Future 的简单使用
- vivoy73s和荣耀30青春版的区别
猜你喜欢
QT hybrid Python development technology: Python introduction, hybrid process and demo
Is blazor ready to serve the enterprise?
2020-11-05
个人短网址生成平台 自定义域名、开启防红、统计访问量
高并发,你真的理解透彻了吗?
swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
What? Your computer is too bad? You can handle these moves! (win10 optimization tutorial)
PerconaXtraDBCluster8.0 最详尽用法指南
Unparseable date: 'Mon Aug 15 11:24:39 CST 2016',时间格式转换异常
PX4添加新的应用
随机推荐
Visual studio 2015 unresponsive / stopped working problem resolution
vivoS7e和vivoS7的区别 哪个更值得入手
What details does C + + improve on the basis of C
Which is more worth starting with the difference between vivos7e and vivos7
sed之查找替换
M 端软件产品设计思虑札记 - 知乎
QT hybrid Python development technology: Python introduction, hybrid process and demo
高并发,你真的理解透彻了吗?
Summary of knowledge points of Jingtao project
How did Julia become popular?
C expression tree (1)
Function periodic table filter value selectedvalue
What is the difference between vivoy73s and vivoy70s
print( 'Hello,NumPy!' )
Face recognition: attack types and anti spoofing techniques
异常+abstract
Astra: Apache Cassandra的未来是云原生
iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
Introduction to ucgui
在Ubuntu上体验最新版本EROFS