非递归的算法检索目录及子文件
2013-09-27 10:21
106 查看
1、VC 共享DLL工程
#include <iostream> #include <math.h> #include <conio.h> #include <afxwin.h> #include <shlwapi.h> using namespace std; typedef int(*lpAddFun)(int, int); //宏定义函数指针类型 typedef BOOL (*PROCESS_FILE_FUNCTION)(CString filename); //上面的PROCESS_FILE_FUNCTION是一种函数指针,这个函数处理文件名为filename的文件,如果该函数返回 //FALSE,则ProcessDirectory立刻退出,不再继续查找 void ProcessDirectory(LPCTSTR dirname,PROCESS_FILE_FUNCTION proc,CStringArray &retDirs) { CStringArray dirs; CString searchname; CFileFind find; dirs.Add(dirname); BOOL bRet; while(dirs.GetSize()>0) { searchname = dirs[0] +"\\*.*"; dirs.RemoveAt(0); bRet = find.FindFile (searchname,0); if(!bRet)continue; do{ bRet = find.FindNextFile (); if(find.IsDots ()) {//忽略.和..文件 continue; } if(find.IsDirectory ()) { dirs.Add (find.GetFilePath()); continue; }else{ if(proc(find.GetFilePath ())) { retDirs.Add(find.GetFilePath()); } } }while(bRet); } } BOOL exe(CString filename) { CString ext=PathFindExtension(filename); //修改内容,过滤文件 if(ext.CompareNoCase(_T(".h"))==0) { return TRUE; }else{ return FALSE; } } int main() { CStringArray dirs; ProcessDirectory(_T("d:\\openssl"),(PROCESS_FILE_FUNCTION)exe,dirs); for(int i=0;i<dirs.GetSize();i++) { CString val=dirs.GetAt(i); val.Append(_T("\n")); OutputDebugString(val); } getchar(); return 0; }
相关文章推荐
- ASP检索网站指定目录文件的算法与应用方向
- 递归获取文件的目录和子文件
- 面试题-程序题-Java递归实现遍历文件目录(所有文件夹和子文件)
- php递归查找指定目录下及子文件名称是否包含中文空格括号
- Win32非递归遍历和搜索文件以及目录算法
- Java使用递归找出某目录下的所有子目录以及子文件
- ASP检索网站指定目录文件的算法与应用方向
- 算法:递归列出一个目录下面的所有文件
- ASP检索网站指定目录文件的算法与应用方向
- Win32非递归遍历和搜索文件以及目录算法
- 批量递归转换目录下pdf文件到swf
- 目录帖:浅谈算法和数据结构
- FileHasher:递归计算指定目录的所有文件的hash值,并依据hash值寻找重复的文件(update 2006-05-22)
- 排列组合算法的递归实现
- 【学习笔记】算法竞赛:chapter 3 & 4 数组、字符串;函数、递归
- 蓝桥杯 ALGO-11算法训练 瓷砖铺放(递归/动态规划)
- 递归遍历目录下文件
- 递归删除文件目录
- 数据结构及算法 -- 目录
- 二叉树非递归遍历的算法-有限状态自动机