1 | uses Masks; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | procedure GetFileListEx(FilePath, ExtMask: string; FileList: TStrings; SubDirectory: Boolean = True); function Match(FileName: string; MaskList: TStrings): Boolean; var i: integer; begin Result := False; for i := 0 to MaskList.Count - 1 do begin if MatchesMask(FileName, MaskList[i]) then begin Result := True; break ; end; end; end; var FileRec: TSearchRec; MaskList: TStringList; begin if DirectoryExists(FilePath) then begin if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + ' \ '; if FindFirst(FilePath + ' *.* ', faAnyFile, FileRec) = 0 then begin MaskList := TStringList.Create; try ExtractStrings([' ; '], [], PChar(ExtMask), MaskList); FileList.BeginUpdate; repeat if ((FileRec.Attr and faDirectory) <> 0) and SubDirectory then begin if (FileRec.Name <> ' . ') and (FileRec.Name <> ' .. ') then GetFileListEx(FilePath + FileRec.Name + ' \', ExtMask, FileList); end else begin if Match(FilePath + FileRec.Name, MaskList) then FileList.Add( FilePath + FileRec.Name); end; until FindNext(FileRec) <> 0; FileList.EndUpdate; finally MaskList.Free; end; end; FindClose(FileRec); end; end; |
1 2 | Memo1.Lines.Clear; GetFileListEx(edit1.Text, '*.txt' ,Memo1.Lines, true ); |
已经验证过,已使用.代码没问题…
标签:delphi
发表评论