当前位置:网站首页>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
边栏推荐
- 将“光头”识别为“足球”,AI 摄像头如何犯的错?
- 技术人员该如何接手一个复杂的系统?
- VC6兼容性及打开文件崩溃问题解决
- 鼠标变小手
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- 函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
- Game optimization performance (11) - Zhihu
- Littlest JupyterHub| 02 使用nbgitpuller分发共享文件
- Blazor 准备好为企业服务了吗?
- 个人短网址生成平台 自定义域名、开启防红、统计访问量
猜你喜欢

PCIe 枚举过程

FORTRAN77从文件中读入若干数据并用heron迭代公式开方

Astra: Apache Cassandra的未来是云原生

Mate 40 series launch with Huawei sports health service to bring healthy digital life

vivoS7e和vivoS7的区别 哪个更值得入手

Face recognition: attack types and anti spoofing techniques

Seven features of Python 3.9

IOS upload app store error: this action cannot be completed - 22421 solution

解决RabbitMQ消息丢失与重复消费问题

1. In depth istio: how is sidecar auto injection realized?
随机推荐
Is blazor ready to serve the enterprise?
PCIe 枚举过程
糟糕,系统又被攻击了
面部识别:攻击类型和反欺骗技术
Search and replace of sed
Review the cloud computing application scenarios you didn't expect (Part 1)
来自不同行业领域的50多个对象检测数据集
The most detailed usage guide for perconaxtradbcluster8.0
1. In depth istio: how is sidecar auto injection realized?
Improvement of rate limit for laravel8 update
C++在C的基础上改进了哪些细节
2020-11-07:已知一个正整数数组,两个数相加等于N并且一定存在,如何找到两个数相乘最小的两个数?
Windows subsystem Ubuntu installation
分布式共识机制
FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem
The real-time display of CPU and memory utilization rate by Ubuntu
Brief history of computer
PX4添加新的应用
sed之查找替换
Test requirements for MIC certification of Bluetooth 2.4G products in Japan