试验一下这个,也许可以。匆忙写的,没有严格测试
procedure GetFilesInfo(aFilePath, aFileExt: String; var astrlist: TStringList);
var
SR: TSearchRec;
begin
{获取当前目录下的文件}
if FindFirst(aFilePath + aFileExt, faReadOnly + faHidden + faSysFile + faArchive, SR) = 0 then
begin
aStrList.Add(sr.Name);
while FindNext(Sr) = 0 do
aStrList.Add(sr.Name);
FindClose(Sr);
end;
{递归查找子目录下的文件}
if FindFirst(aFilePath + '*.*', faDirectory, SR) = 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') then
GetFilesInfo(aFilePath + sr.Name + '/', aFileExt, astrlist);
while FindNext(SR) = 0 do
if (sr.Name <> '.') and (sr.Name <> '..') then
GetFilesInfo(aFilePath + sr.Name + '/', aFileExt, astrlist);
end;
FindClose(sr);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aa: TStringList;
begin
aa := TStringList.Create;
GetFilesInfo('C:/Windows/', '*.TXT', aa);
ShowMessage(aa.Text);
aa.Free;
end;