procedure Tform1.FileSearch(PathName:string);
var
F : TSearchRec;
Found : Boolean;
begin
ChDir(PathName);
Found := (FindFirst('*.*', faDirectory, F) = 0);
while Found do
begin
if (F.Name = '.') or (F.Name = '..') then
begin
Found := (FindNext(F) = 0);
Continue;
end;
if (F.Attr and faDirectory)>0 then
begin
Application.ProcessMessages;
FileSearch(F.Name);
end;
Found := (FindNext(F) = 0);
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cols[0].Add(GetCurrentDir);
StringGrid1.Cols[1].Add(F.name);
end;
FindClose(F);
ChDir('../');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FileSearch('C:/ACD/');
StringGrid1.ColWidths[0] := 300;
end;
//然后对StringGrid做一个排序就行了,这个你应该会了吧。