吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 825|回复: 7
收起左侧

[求助] 求教 怎么遍历取到子文件夹名?

[复制链接]
冥界3大法王 发表于 2021-9-25 11:49
[Delphi] 纯文本查看 复制代码
uses
  SysUtils, StrUtils, Masks;




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;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox1.Items := MakeFileList('X:\要遍历的文件夹', '.*');
end;

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

batcd 发表于 2021-9-25 12:19
你这个语言我不会,但是遍历文件夹用递归是最好的了
风景暗色调 发表于 2021-9-25 12:30
DEATHTOUCH 发表于 2021-9-25 13:56
用 System.IOUtils 单元
里面有 TDirectory.GetDirectories 可以用
用法:
[Delphi] 纯文本查看 复制代码
TDirectory.GetDirectories(path, '*.*', TSearchOption.soAllDirectories);

他会自动递归查找所有文件夹

免费评分

参与人数 1吾爱币 +1 收起 理由
冥界3大法王 + 1 谢谢@Thanks!

查看全部评分

DEATHTOUCH 发表于 2021-9-25 14:08
本帖最后由 DEATHTOUCH 于 2021-9-25 14:15 编辑
DEATHTOUCH 发表于 2021-9-25 13:56
用 System.IOUtils 单元
里面有 TDirectory.GetDirectories 可以用
用法:

TDirectory里还有查找所有子文件夹内文件的函数GetFiles
Atnil 发表于 2021-9-25 14:52
...用递归函数...这一定是在钓鱼
大法王怎么可能不知道递归
话说这Delphi风格的SmartPascal代码是怎么肥思?
 楼主| 冥界3大法王 发表于 2021-9-25 16:41
DEATHTOUCH 发表于 2021-9-25 13:56
用 System.IOUtils 单元
里面有 TDirectory.GetDirectories 可以用
用法:

感谢 各位找到了这个https://blog.csdn.net/weixin_30747253/article/details/97430839
 楼主| 冥界3大法王 发表于 2021-9-25 17:18
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-4 02:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表