[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;
|