• Delphi遍历文件夹及子文件夹(可查找固定格式文件)


    Delphi遍历文件夹及子文件夹

    {-------------------------------------------------------------------------------
    过程名:    MakeFileList 遍历文件夹及子文件夹
    作者:      SWGWEB
    日期:      2007.11.25
    参数:      Path,FileExt:string   1.需要遍历的目录 2.要遍历的文件扩展名
    返回值:    TStringList

       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;

     

  • 相关阅读:
    找回感觉的练习
    第四次博客作业-结对项目
    zookeeper启动脚本
    docker自己制作centos7-jdk1.8-tomcat8
    Docker运行springboot的项目
    从list中模糊查询字符串
    Java实现文件下载
    hadoop的HA集群搭建
    oauth2 feign 报401的错误
    SpringBoot mybatis 自定义分页插件 注解版
  • 原文地址:https://www.cnblogs.com/qingsong/p/3507260.html
Copyright © 2020-2023  润新知