博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Delphi下遍历文件夹下所有文件的递归算法
阅读量:7103 次
发布时间:2019-06-28

本文共 1149 字,大约阅读时间需要 3 分钟。

{-------------------------------------------------------------------------------
过程名:    MakeFileList 遍历文件夹及子文件夹
参数:      Path,FileExt:string   1.需要遍历的目录 2.要遍历的文件扩展名
返回值:    TStringList
USE StrUtils
   Eg:ListBox1.Items:= MakeFileList( 'E:\极品飞车','.exe') ;
       ListBox1.Items:= MakeFileList( 'E:\极品飞车','.*') ;
-------------------------------------------------------------------------------}
function MakeFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;
if rightStr(trim(Path), 1) <> '\' then
    Path := trim(Path) + '\'
else
    Path := trim(Path);
if not DirectoryExists(Path) then
begin
    Result.Clear;
    exit;
end;
if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
    repeat
       Application.ProcessMessages;
       if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
       if DirectoryExists(Path+sch.Name) then
       begin
         Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
       end
       else
       begin
         if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
         Result.Add(Path+sch.Name);
       end;
    until FindNext(sch) <> 0;
    SysUtils.FindClose(sch);
end;
end;

转载于:https://www.cnblogs.com/jxgxy/archive/2011/07/25/2116651.html

你可能感兴趣的文章
SOA会不会造成IT黑洞
查看>>
查询存储过程所需参数
查看>>
HTML5 Web app开发工具Kendo UI Web教程:如何配置Kendo UI Calendar
查看>>
vue Element动态设置el-menu导航当前选中项
查看>>
session的使用
查看>>
Centos6.8通过yum安装mysql5.7
查看>>
Asp.net 4.0,首次请求目录下的文件时响应很慢
查看>>
hdu-------(1848)Fibonacci again and again(sg函数版的尼姆博弈)
查看>>
GridView编辑删除操作
查看>>
iOS程序的启动图片图标规范
查看>>
动画 -- 按钮 -- 左右晃动
查看>>
mysql+ssh整合样例,附源代码下载
查看>>
WWF3XOML方式创建和启动工作流 <第十篇>
查看>>
IE6 — 你若安好,便是晴天霹雳 [ 乱弹 ]
查看>>
组合数学 - 母函数的运用 --- 模板题
查看>>
检测MYSQL不同步发邮件通知的脚本
查看>>
Struts2学习笔记1
查看>>
python的ftp上传和下载
查看>>
ASP.NET MVC 中的路由
查看>>
微信公众平台帐号通过昵称无法搜索到怎么办
查看>>