给你一个例子: 递归的方法搜寻
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Memo1: TMemo;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure SearchFile(const Directy ,FileName:string);
implementation
{$R *.DFM}
procedure SearchFile(const Directy ,FileName:string);
var
FindRec:TWIN32FindData;
FindHandle :THandle;
FileAttr
WORD ;
FileSearched :String ;
begin
FindHandle := FindFirstFile (pchar(Directy + FileName ),FindRec );
if FindHandle <> INVALID_HANDLE_VALUE
then begin
repeat
FileAttr := FindRec .dwFileAttributes;
FileSearched := string(FindRec .cFileName) ;
begin
Form1 .Memo1 .Lines .Add (Directy +FileSearched );
end;
if ( FileAttr = FILE_ATTRIBUTE_DIRECTORY) and ( FileSearched <> '.')
and ( FileSearched <> '..')
then begin
SearchFile (Directy+FileSearched +'/' ,FileName );
end;
until FindNextFile (FindHandle ,FindRec ) = false ;
end ;
windows. FindClose(FindHandle );
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SearchFile ('c:/','*.*');
end;
end.