还有这样的好事情。。专门找我??????思想:就是用findfirst findnext查找。关于这两个函数,你参看DELPHI的帮助。 例子:在窗体中定义一个函数findds,接收3个参数,Astrings是要把这些信息写道那里,apath是路径,sourfile是通配符,一把就*.* procedure TForm1.Findds(AStrings: TStrings; APath, Sourfile: string); var FSearchRec : TSearchRec; FindResult : integer; TmpList:TStringList; i : integer; function IsDirNot(A : string) : boolean; begin Result := (a = '.') or (a = '..'); end; begin try TmpList:=TStringList.Create; TmpList.Clear; FindResult := FindFirst(Apath+Sourfile,faDirectory,FSearchRec); while FindResult = 0 do begin if ((FSearchRec.Attr and fadirectory) = faDirectory) then begin if not IsDirNot(FSearchRec.Name) then begin tmplist.Add(apath+FSearchRec.Name); //如果你还需要查找目录下的所有目录,就要用下面这一句,如果只需要查找project下的其它目录,那么就不用了。 //Findds(AStrings, APath + FSearchRec.Name + '\',Sourfile); end; end; FindResult := FindNext(FSearchRec); end; for i := 0 to TmpList.Count -1 do AStrings.Add(TmpList.Strings[i]); TmpList.Free; finally FindClose(FSearchRec); end; end;
例子:在窗体中定义一个函数findds,接收3个参数,Astrings是要把这些信息写道那里,apath是路径,sourfile是通配符,一把就*.*
procedure TForm1.Findds(AStrings: TStrings; APath, Sourfile: string);
var
FSearchRec : TSearchRec;
FindResult : integer;
TmpList:TStringList;
i : integer;
function IsDirNot(A : string) : boolean;
begin
Result := (a = '.') or (a = '..');
end;
begin
try
TmpList:=TStringList.Create;
TmpList.Clear;
FindResult := FindFirst(Apath+Sourfile,faDirectory,FSearchRec);
while FindResult = 0 do
begin
if ((FSearchRec.Attr and fadirectory) = faDirectory) then
begin
if not IsDirNot(FSearchRec.Name) then begin
tmplist.Add(apath+FSearchRec.Name);
//如果你还需要查找目录下的所有目录,就要用下面这一句,如果只需要查找project下的其它目录,那么就不用了。
//Findds(AStrings, APath + FSearchRec.Name + '\',Sourfile);
end;
end; FindResult := FindNext(FSearchRec);
end;
for i := 0 to TmpList.Count -1 do
AStrings.Add(TmpList.Strings[i]);
TmpList.Free;
finally
FindClose(FSearchRec);
end;
end;
Findds(Memo1.Lines, Edit1.Text,'*.*');edit1.text是要查找的目录,例如;d:\text\(要有最后这个\,不可省略,除非你在程序总加判断)
memo1.lines,就是将查询结果写到那里,你也可以用ListBox1.Items