当前位置:网站首页>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
边栏推荐
- 在Ubuntu上体验最新版本EROFS
- An error occurred while starting the kernel was successfully resolved
- Review the cloud computing application scenarios you didn't expect (Part 1)
- Introduction to ucgui
- Fgagt: flow guided adaptive graph tracking
- Deeplight Technology Bluetooth protocol SRRC certification services
- swiper 窗口宽度变化,页面宽度高度变化 导致自动滑动 解决方案
- 架构师(2020年11月)
- How did Julia become popular?
- Summary of knowledge points of Jingtao project
猜你喜欢

NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)

Rust: command line parameter and environment variable operation

China Telecom announces 5g SA commercial scale in 2020

Fgagt: flow guided adaptive graph tracking

python_ scrapy_ Fang Tianxia

5G+AR出圈,中国移动咪咕成第33届中国电影金鸡奖全程战略合作伙伴

That's what software testing is all about?!

vivoy73s和荣耀30青春版的区别

5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award

More than 50 object detection datasets from different industries
随机推荐
PCR and PTS calculation and inverse operation in TS stream
Is blazor ready to serve the enterprise?
NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)
Solve Safari browser download file name garbled problem
Rust: command line parameter and environment variable operation
Qt混合Python开发技术:Python介绍、混合过程和Demo
How can a technician take over a complex system?
Experience the latest version of erofs on Ubuntu
Mouse small hand
Visual studio 2015 unresponsive / stopped working problem resolution
Shiyou's numerical analysis assignment
Distributed consensus mechanism
QT hybrid Python development technology: Python introduction, hybrid process and demo
抖音直播监控Api:随机推荐
双向LSTM在时间序列异常值检测的应用
C expression tree (1)
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
高并发,你真的理解透彻了吗?
print( 'Hello,NumPy!' )
Search and replace of sed