-
Notifications
You must be signed in to change notification settings - Fork 38
/
FindAllFilesEnhanced.pas
executable file
·61 lines (49 loc) · 1.46 KB
/
FindAllFilesEnhanced.pas
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
52
53
54
55
56
57
58
59
60
61
unit FindAllFilesEnhanced;
// An enhanced version of the FPC FindAllFiles routine that will detect hidden files
// and hidden files inside hidden directories. Credit to users EngKin and Bart from
// the forums for quickly developing this unit
{$mode objfpc}{$H+} // {$H+} ensures strings are of unlimited size
interface
uses
LazUTF8Classes, Classes;
function FindAllFilesEx(const SearchPath: string; SearchMask: string;
SearchSubDirs: boolean; IncludeHiddenDirs: boolean): TStringListUTF8;
implementation
uses
FileUtil,
SysUtils; //for faHidden
type
{ TListFileSearcher }
TListFileSearcher = class(TFileSearcher)
private
FList: TStrings;
protected
procedure DoFileFound; override;
public
constructor Create(AList: TStrings);
end;
{ TListFileSearcher }
procedure TListFileSearcher.DoFileFound;
begin
FList.Add(FileName);
end;
constructor TListFileSearcher.Create(AList: TStrings);
begin
inherited Create;
FList := AList;
end;
function FindAllFilesEx(const SearchPath: string; SearchMask: string;
SearchSubDirs: boolean; IncludeHiddenDirs: boolean): TStringListUTF8;
var
Searcher: TListFileSearcher;
begin
Result := TStringListUTF8.Create;
Searcher := TListFileSearcher.Create(Result);
Searcher.DirectoryAttribute := Searcher.DirectoryAttribute or faHidden;
try
Searcher.Search(SearchPath, SearchMask, SearchSubDirs);
finally
Searcher.Free;
end;
end;
end.