只能一个个的找了:
procedure SearchDir(WatchSubTree:Boolean;MainPath:String;SubTree:Boolean);
var i:Integer;
Found:Boolean;
SubDir:TSTringList;
SearchRec:TsearchRec;
S:String;
begin
if DirectList=nil then DirectList:=TStringList.Create;
if not SubTree then DirectList.Clear;
SubDir:=TStringList.Create;
if MainPath[Length(MainPath)]='/' then S:=MainPath
else S:=MainPath+'/';
if DirectoryExists(MainPath) then begin
//第一次遍历时加上本目录
if DirectList.Count=0 then DirectList.Add(MainPath+'/');
//找出所有下级子目录
if (FindFirst(S+'*.*', faDirectory, SearchRec)=0) then begin
if IsValidDir(SearchRec) then begin
SubDir.Add(SearchRec.Name);
DirectList.Add(S+SearchRec.Name+'/');
end;
while (FindNext(SearchRec) = 0) do begin
if IsValidDir(SearchRec) then begin
SubDir.Add(SearchRec.Name);
DirectList.Add(S+SearchRec.Name+'/');
end;
end;
end;
end;
if WatchSubTree then begin
//递归:查找各子目录
for i:=0 to SubDir.Count-1 do
SearchDir(True,S+SubDir.Strings
+'/',True);
end;
end;
procedure GetAllFileNames(SearchDir:Boolean;WatchSubTree:Boolean=False;FileNameExt:String='');
var SearchRec: TSearchRec;
TempList:TStrings;
PFileCollection;
i,iExt:Integer;
J:Boolean;
SL:TStringList;
ValidateDir:Boolean;
S:String;
begin
if FileList<>nil then begin
for i:=0 to FileList.Count-1 do begin
P:=PFileCollection(FileList);
Dispose(P);
end;
FreeAndNil(FileList);
end;
FileList:=TList.Create;
SL:=TStringList.Create;
if Trim(FileNameExt)='' then exit;
splite(UpperCase(Trim(FileNameExt)),',',SL);
for iExt:=0 to SL.Count-1 do begin
for i:=0 to DirectList.Count-1 do begin
if not SearchDir then ValidateDir:=True
else begin
if Uppercase(Trim(GetFactPath(DirectList)))=
Uppercase(Trim(GetFactPath(SysDateDir))) then ValidateDir:=True
else ValidateDir:=False;
end;
if ValidateDir then begin
S:=GetFactPath(DirectList)+'*.'+Trim(SL[iExt]);
if FindFirst(S,faArchive,SearchRec)=0 then begin
J:=True;
New(P);
P.FileName:=SearchRec.Name;
P.DirPath:=DirectList;
P.FileSize:=SearchRec.Size;
P.ModifyTime:=FileDateToDateTime(SearchRec.Time);
FileList.Add(P);
while FindNext(SearchRec)=0 do begin
New(P);
P.FileName:=SearchRec.Name;
P.DirPath:=DirectList;
P.FileSize:=SearchRec.Size;
P.ModifyTime:=FileDateToDateTime(SearchRec.Time);
FileList.Add(P);
end;
end;
end;
end;
end;
//FindClose(SearchRec);
end;