//函数名: FindDisk
//参数:
// PathName:string 路径
//返回:无
//描述: 本函数将搜索指定路径下面的所有扩展名在FilterString中的文件,
// BSSubDirectory标志是真,则搜索指定目录下面的所有子目录.并且将
// 搜索到的文件名(含全路径)添加到FileList列表中.可以搜索只读文
// 件和隐藏文件.
procedure TFrmAceptXj.FindDisk(PathName:String );
var
fRec :TSearchRec;
filestring,tmpPathName,tmpstring:String ;
HaveBeen:boolean;
iLen:integer;
i:integer;
begin
iLen:=StrLen(PChar(PathName));
if(PathName[iLen]<>'/')then
begin
PathName:=PathName+'/';
end;
tmpPathName:=PathName+'*.*';
//找第一个文件
if(FindFirst(tmpPathName,faAnyFile,fRec)=0 ) then
begin
if((fRec.Attr>=faDirectory) and
(fRec.Attr <= 19 )) then //faDirectory+nfaReadOnly +faHidden
begin //如是目录
if((fRec.Name<>'.') and (fRec.Name <> '..'))then
begin
tmpPathName := PathName + fRec.Name+'/';
if(BSSubDirectory=true)then//是否搜索子目录
FindDisk(tmpPathName); //递归调用本身
end
end
else
begin //不是目录
HaveBeen:=false;
for i:=0 to FFilterCount-1 do
begin
//是否在条件内
tmpstring:= StrLower(PChar(fRec.Name));
if(StrPos(PChar(tmpstring),PChar(FilterString))<> nil)then
begin
HaveBeen:=true;
break;
end;
end ;
if(HaveBeen= true) then
begin //如符合条件
FileList.Add(PathName + Trim(fRec.Name));
end
end;
end
else exit;
while(true) do
begin
if(FindNext(fRec)=0 )then
begin
if((fRec.Attr>=faDirectory)and(fRec.Attr<=19)) then
begin
if((fRec.Name<>'.') and ( fRec.Name<>'..'))then
begin
tmpPathName := PathName +Trim(fRec.Name) + '/';
if(BSSubDirectory =true)then // //是否搜索子目录
FindDisk(tmpPathName);
end;
end
else
begin
HaveBeen:=false;
for i:=0 to FFilterCount-1 do
begin
tmpstring:= StrLower(PChar(fRec.Name));
if(StrPos(PChar(tmpstring),PChar(FilterString))<> nil)then
begin
HaveBeen:=true;
break;
end;
end;
if(HaveBeen=true )then
begin
FileList.Add(PathName + trim(fRec.Name));
end;
end;
end
else break;
end;
end;