当前位置:网站首页>VC + + specified directory file output by time
VC + + specified directory file output by time
2020-11-08 09:40:00 【osc_4punxmqt】
function : Get all the files in a specified directory , Then save it in chronological order , Generally used for interface display , Or file list sorting function ...
// Sort
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;
}
}
// Acquisition time
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;
}
// Find the files in the directory
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]所创,转载请带上原文链接,感谢
边栏推荐
- Shiyou's numerical analysis assignment
- laravel8更新之速率限制改进
- 接口
- How does spotify drive data-driven decision making?
- 模板链表类学习
- 将“光头”识别为“足球”,AI 摄像头如何犯的错?
- python_scrapy_房天下
- Improvement of rate limit for laravel8 update
- Deeplight Technology Bluetooth protocol SRRC certification services
- Daily challenges of search engines_ 4_ External heterogeneous resources - Zhihu
猜你喜欢
2020-11-05
IOS upload app store error: this action cannot be completed - 22421 solution
Template linked list learning
More than 50 object detection datasets from different industries
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
SQL Server 2008R2 18456错误解决方案
Oops, the system is under attack again
成功解决An error ocurred while starting the kernel
Deeplight Technology Bluetooth protocol SRRC certification services
分布式共识机制
随机推荐
Rust:命令行参数与环境变量操作
来自不同行业领域的50多个对象检测数据集
iOS上传App Store报错:this action cannot be completed -22421 解决方案
Is blazor ready to serve the enterprise?
Visual Studio 2015 未响应/已停止工作的问题解决
解决RabbitMQ消息丢失与重复消费问题
模板链表类学习
Unparseable date: 'mon Aug 15 11:24:39 CST 2016', time format conversion exception
个人短网址生成平台 自定义域名、开启防红、统计访问量
个人目前技术栈
ASP.NET A complete solution based on exception handling in MVC
More than 50 object detection datasets from different industries
“1024”征文活动结果新鲜出炉!快来看看是否榜上有名?~~
Shiyou's numerical analysis assignment
ASP.NET MVC下基于异常处理的完整解决方案
技术人员该如何接手一个复杂的系统?
进程、线程和协程的区别
Review the cloud computing application scenarios you didn't expect (Part 1)
python 循环区分(while循环和for循环)
Python learning Day1 -- Basic Learning