遍历文件

procedure FindFiles(sPath, sFileExt: string; AStrs: TStrings; SubDir: Boolean;ShowDir: Boolean); var FSrchRec{, DSrchRec}: TSearchRec; nFindResult: Integer; nSearchMode: Integer; begin nSearchMode := faAnyFile + faDirectory; nFindResult := FindFirst( sPath + sFileExt, nSearchMode, FSrchRec); try while nFindResult = 0 do begin //排除对应当前目录的两个结果 if (FSrchRec.Name <> '.') and (FSrchRec.Name <> '..') then begin //如果是目录,根据参数决定结果中是否包含子目录、是否搜索子目录 if (FSrchRec.Attr and faDirectory) = faDirectory then begin if ShowDir then // 是否显示目录 AStrs.Add(sPath + GetValidPath(FSrchRec.Name)); if SubDir then [color=#FF0000]// 是否搜索子目录模式,是则递归搜索子目录[/color] FindFiles(sPath + FSrchRec.Name, sFileExt, AStrs, SubDir, ShowDir); end else AStrs.Add(sPath + FSrchRec.Name); end; nFindResult := FindNext(FSrchRec); end; finally FindClose(FSrchRec); end; end;

你可能感兴趣的:(遍历文件)