- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 获取指定当前目录下指定文件扩展名所有文件
procedure MakeFileList(const Path, FileExt: string; AFileList: TStrings);
var
sch: TSearchRec;
tmpPath: string;
begin
if RightStr(Trim(Path), 1) <> '\' then
tmpPath := Trim(Path) + '\'
else
tmpPath := Trim(Path);
if not DirectoryExists(tmpPath) then
Exit;
if FindFirst(tmpPath + '*', faAnyFile, sch) = 0 then
begin
repeat
if ((sch.Name = '.') or (sch.Name = '..')) then
Continue;
if (UpperCase(ExtractFileExt(tmpPath + sch.Name)) = UpperCase(FileExt)) or (FileExt = '.*') then
AFileList.Add(tmpPath + sch.Name);
until FindNext(sch) <> 0;
System.SysUtils.FindClose(sch);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MakeFileList('c:\','.exe',memo1.Lines);
end;