function FindFilePath(Path,FileName: string): string;
var
RFileName:string;
sr: TSearchRec;
FileAttrs:Integer;
begin
Application.ProcessMessages;
FileAttrs := faDirectory;
RFileName := FileSearch(filename,path);
if (RFileName = '') then begin
if FindFirst(path + '/*.*',FileAttrs,sr) = 0 then begin
repeat
if (((sr.Attr and FileAttrs) = sr.Attr) and (sr.Name <> '.') and (sr.Name <> '..')) then
begin //如果为目录,则递归
aa.Add(Path + '/' + sr.Name) ;
RFileName := FindFilePath(Path + '/' + sr.Name,FileName);
if (RFileName <> '') then begin
result := RFileName;
exit;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
result := RFileName;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
Path : String;
FilePath : String;
begin
FilePath :='*.*';
aa := TStringlist.Create;
Path := 'F:/NetGame1/大话西游';
FindFilePath(path,'');
ListBox2.Items := aa;
ListBox1.Items.Add(Path);
SetCurrentDirectory(Pchar(Path));
SendMessage(ListBox1.Handle, LB_DIR, DDL ,LPARAM(FilePath));
for i:=0 to aa.Count-1 do
begin
ListBox1.Items.Add(aa.Strings[i]);
SetCurrentDirectory(Pchar(aa.Strings[i]));
SendMessage(ListBox1.Handle, LB_DIR, DDL ,LPARAM(FilePath));
end;
end;