文件遍历函数
来源:互联网 发布:github上的源码怎么用 编辑:程序博客网 时间:2024/04/29 22:09
void BrowseDir(CString strDir) //此函数用于遍历文件夹下的文件,strDir是一个目录路径
{
if(strDir == "")
{
MessageBox("error!");
return;
}
CFileFind ff;
CString szDir = strDir,strPath;
if(szDir.Right(1) != "//") //保证目录是以/结尾的
szDir += "//";
szDir += "*.*";
BOOL res = ff.FindFile(szDir);
while( res )
{
res = ff.FindNextFile();
strPath = ff.GetFilePath();
if(ff.IsDirectory() && !ff.IsDots())
BrowseDir(strPath); //如果目标是个文件夹,则利用嵌套来遍历
else if(!ff.IsDirectory() && !ff.IsDots())
DoSth(strPath); //如果目标是个文件,则对它进行处理
}
ff.Close();
}
void ListFolder(CString sPath){
CFileFind ff;
BOOL bFound = ff.FindFile(sPath + "//*.*");
while(bFound){ bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory()){
if(!ff.IsDots())
ListFolder(sFilePath);
} else ListFile(sFilePath);//这里记录的就是所有的文件
}
ff.Close();
}
step 1:
得到目录下所有文件存入m_strArrFilename.
//xxx.h
CStringArray m_strArrFilename;
//xxx.cpp
void CTest6Dlg::OnButton1()
{
FindMyFile("D://1//");
CString str="";
}
void CTest6Dlg::FindMyFile(CString path)
{
BOOL bFind, bFindSuffix;
CFileFind tempFind, tempFind1;
_chdir(path);
bFind = tempFind.FindFile("*.*");
while(bFind)
{
bFind = tempFind.FindNextFile();
if(tempFind.IsDirectory())
{
if (!tempFind.IsDots() )
{
CString temppath;
temppath = tempFind.GetFilePath();
FindMyFile(temppath);
}
}
}
_chdir(path);
bFindSuffix = tempFind1.FindFile("*.*");
while(bFindSuffix)
{
bFindSuffix = tempFind1.FindNextFile();
CString filepath, filename;
if( !tempFind1.IsDirectory() && !tempFind1.IsDots())
{
filepath = tempFind1.GetFilePath();
m_strArrFilename.Add(filepath);
}
}
tempFind.Close();
tempFind1.Close();
}
-----------------------------------------------
step 2:
得到文件的一些属性,并比较时间
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(m_strArrFilename[0], &ffd);
FILETIME ftCreationTime = ffd.ftCreationTime;
FILETIME ftLastWriteTime = ffd.ftLastWriteTime;
然后比较所有文件的时间,进行排序。。。
- 文件遍历排序函数
- 文件遍历函数
- 文件遍历排序函数
- 文件遍历排序函数
- 一个文件遍历小函数的设计
- 遍历所有文件和目录的函数
- 使用Dir函数遍历文件和目录
- 遍历函数
- fso遍历某一目录下所有文件的函数
- VB用API函数遍历指定驱动器、目录的文件
- 遍历显示文件夹下所有目录、所有文件的函数
- 遍历指定目录下指定类型文件的函数
- 遍历删除一个目录下所有文件的函数
- 遍历文件夹文件的函数(FTP方式)
- PHP ZipArchive::extractTo()函数.zip文件目录遍历漏洞
- 遍历目录下的指定扩展名文件的函数
- php遍历文件夹所有文件子文件夹函数
- delphi遍历指定目录下指定类型文件的函数
- 转一篇介绍开发嵌入式经验的文章,写得不错,比较中肯,适合一看。 (转)
- 动态库静态库真苦手
- 山海演武传·黄道·第一卷 雏龙惊蛰 第七章 人与神兽的竞争
- API是什么
- MapWindowPoints
- 文件遍历函数
- [从jQuery看JavaScript]-JavaScript
- 山海演武传·黄道·第一卷 雏龙惊蛰 第八章 化外自成国
- UNICODE下的字符转换
- Microsoft Project
- 山海演武传·黄道·第一卷 雏龙惊蛰 第九章 明月之王
- 未能导入activex 控件的解决方法
- 山海演武传·黄道·第一卷 雏龙惊蛰 第十章 天下英雄在谱中(上)
- 文件通配符函数