当前位置:网站首页>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
边栏推荐
- ASP.NET A complete solution based on exception handling in MVC
- 软件测试就是这么回事?!
- 分布式共识机制
- Deeplight Technology Bluetooth protocol SRRC certification services
- vivoY73s和vivoY70s的区别 vivoY73s和vivoY70s哪个值得入手
- nvm
- 个人短网址生成平台 自定义域名、开启防红、统计访问量
- python_scrapy_房天下
- Cloud alibabab notes come out, the whole network detailed explanation only this one hand is slow
- 游戏优化性能杂谈(十一) - 知乎
猜你喜欢
Visual studio 2015 unresponsive / stopped working problem resolution
糟糕,系统又被攻击了
蓝牙2.4G产品日本MIC认证的测试要求
Littlest jupyterhub| 02 using nbgitpuller to distribute shared files
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
IOS learning note 2 [problems and solutions encountered during the installation and use of cocopods] [update 20160725]
Fgagt: flow guided adaptive graph tracking
FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
将“光头”识别为“足球”,AI 摄像头如何犯的错?
随机推荐
ASP.NET A complete solution based on exception handling in MVC
Distributed consensus mechanism
The difference between vivoy 73s and glory 30 Youth Edition
Julia 是如何风靡起来的?
Unparseable date: 'mon Aug 15 11:24:39 CST 2016', time format conversion exception
Face recognition: attack types and anti spoofing techniques
M 端软件产品设计思虑札记 - 知乎
SQL Server 2008R2 18456错误解决方案
Is there a big difference between i5 1135g7 and i51035g1? Which is better?
麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
异常+abstract
Insight -- the application of sanet in arbitrary style transfer
1. In depth istio: how is sidecar auto injection realized?
How did Julia become popular?
How does spotify drive data-driven decision making?
Simple use of future in Scala
An error occurred while starting the kernel was successfully resolved
Deeplight Technology Bluetooth protocol SRRC certification services
Mouse small hand
Architect (November 2020)