如果遍历一个目录下的所有子目录(50分)

  • 主题发起人 主题发起人 superplayboy
  • 开始时间 开始时间
S

superplayboy

Unregistered / Unconfirmed
GUEST, unregistred user!
最好能贴出代码
 
用控件吗
(在win31项里)
 
//-----------获得文件列表--------------------------------------------------------------------------
FUNCTION FkFileListGet(vMask,vFolder:STRING;vSub:BOOL):TStringList;
VAR
sTemp,sProc,sResult:STRING;
k,m,n:Integer;
srList: TSearchRec;
DirList,Filelist,TempList: TStringList;
oFound: Boolean;
intOldAttr: integer;
fileSearch:Integer;
BEGIN
// 建立一个文件夹列表
DirList := TStringList.Create;
FileList := TStringList.Create;
TempList := TStringList.Create;

vFolder:=TRIM(vFolder);
IF vFolder[length(vFolder)]<>'/' THEN vFolder:=vFolder + '/';
// 生成文件夹列表
oFound:=FindFirst(vFolder+'*.*',(faDirectory+faHidden+faSysFile+faReadOnly), srList) = 0;
WHILE oFound DO
BEGIN
IF (DirectoryExists(vFolder+srList.Name) and (srList.Name<>'.') AND (srList.Name<>'..')) THEN
BEGIN
DirList.Add(vFolder+srList.Name);
END;
oFound :=(FindNext(srList)=0);
END;
FindClose(srList);

//查找当前目录的文件
oFound:=FindFirst(vFolder+vMask,(faAnyFile+faHidden+faSysFile+faReadOnly), srList) = 0;
WHILE oFound DO
BEGIN
IF FileExists(vFolder+srList.Name) THEN
BEGIN
intOldAttr:=FileGetAttr(vFolder+srList.Name);
FileSetAttr(vFolder+srList.Name,0);
fileSearch:=FileOpen(vFolder+srList.Name,fmOpenReadWrite);
IF fileSearch>0 THEN
BEGIN
FileClose(fileSearch);
FileSetAttr(vFolder+srList.Name,intOldAttr);
FileList.Add(vFolder+srList.Name);
END;
END;
oFound :=(FindNext(srList)=0);
END;
FindClose(srList);
//查找列表的子目录
IF vSub THEN
BEGIN
FOR k := 0 TO DirList.Count-1 DO
BEGIN
TempList:=FkFileListGet(vMask,DirList[k],vSub);
FOR m:=0 TO TempList.Count-1 DO FileList.Add(TempList[m]);
END;
END;
DirList.Free; TempList.Free;
Result:=FileList;
END;
//-------------------------------------------------------------------------------------
vMask文件通配
vFolder 文件夹
vSub是否搜索子目录
 
接受答案了.
 
后退
顶部