FindFirst,FindNext,FindClose学习
2012-02-08 18:11
274 查看
procedure TForm1.Button1Click(Sender: TObject); var Dir: TSearchRec; //文件结构 begin if FindFirst(edit1.Text,faAnyFile,Dir) = 0 then begin repeat //是目录吗? //and 的作用是通过 "与" fadirectory 消掉Attr中的其它文件,只取留下faDirectory属性 //通过 or 可以添另其它属性 if(Dir.Attr and faDirectory) = faDirectory then begin ListBox1.Items.Add(dir.Name); if (dir.Name <> '.') and (dir.name <> '..') then GetSubDir('','D:\'+dir.Name,5,true); end; until (FindNext(Dir) <> 0); end; FindCLose(Dir); end; procedure TForm1.GetSubDir(Filter, Folder: string;TreeLevel:Integer; Recurse: boolean); var Dir: TSearchRec; count :Integer; begin count := 0; Folder :=IncludeTrailingPathDelimiter(Folder); if FindFirst(Folder+'*.*',faDirectory,Dir) = 0 then begin repeat //是目录吗? //and 的作用是通过 "与" fadirectory 消掉Attr中的其它文件,只取留下faDirectory属性 //通过 or 可以添另其它属性 if(Dir.Attr and faDirectory) = faDirectory then begin if (dir.Name <> '.') and (dir.name <> '..') then begin inc(count); //文件深度count if(count > TreeLevel) then break; ListBox1.Items.Add(dir.Name); if Recurse then GetSubDir('',Folder+dir.Name,2,Recurse); //递归调用获取子目录 end; end; until (FindNext(Dir) <> 0); end; FindCLose(Dir); end;
相关文章推荐
- FindFirst,FindNext,FindClose
- FindFirstFile、FindNextFile和FindClose
- _findfirst _findnext _findclose 文件(夹)不能删除
- findfirst findnext 递归查找指定目录下所有子目录下所有文件,为什么总是死机?
- 使用FindFirstFile,FindNextFile遍历一个文件夹
- Windows API 之 FineFirstFile、FindNextFile
- 使用FindFirstFile,FindNextFile遍历一个文件夹
- C/C++:遍历子目录,枚举文件,FindFirstFile + FindNextFile
- 遍历目录 常用FindFirstFile()和FindNextFile()
- FtpFindFirstFile和InternetFindNextFile遍历ftp文件
- C/C++:遍历子目录,枚举文件,FindFirstFile + FindNextFile
- c#调用api(FindFirstFile,FindNextFile)高效遍历目录文件
- TClientDataSet[14]: 测试 FindFirst、FindNext、FindLast、FindPrior、Found
- 使用FindFirstFile,FindNextFile遍历一个文件夹
- C/C++:遍历子目录,枚举文件,FindFirstFile + FindNextFile
- FindFirstFile() 和findnextfile()
- 使用FindFirstFile和FindNextFile查找某个目录下的所有文件(包括子目录)
- findfirst findnext
- FtpFindFirstFile()及InternetFindNextFile()对汉字编码的支持问题
- 利用FindFirstFile()以及FindNextFile()函数 实现遍历文件夹里的文件