-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuThreadScanner.pas
71 lines (59 loc) · 1.35 KB
/
uThreadScanner.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
62
63
64
65
66
67
68
69
70
unit uThreadScanner;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil;
type
TFileScannerThread = class(TThread)
private
fPath: string;
fFilter: string;
fList: TStringList;
protected
procedure Execute; override;
procedure FileFoundEvent(FileIterator: TFileIterator);
public
constructor Create;
destructor Destroy; override;
property Path: string read fPath write fPath;
property Filter: string read fFilter write fFilter;
property List: TStringList read fList;
end;
implementation
{ TFileScannerThread }
constructor TFileScannerThread.Create;
begin
inherited Create(true);
FreeOnTerminate:= false;
fPath:= '';
fFilter:= '*.*';
fList:= TStringList.Create;
end;
destructor TFileScannerThread.Destroy;
begin
FreeAndNil(fList);
inherited Destroy;
end;
procedure TFileScannerThread.Execute;
var
Searcher: TFileSearcher;
begin
fPath:= IncludeTrailingPathDelimiter(fPath);
Searcher := TFileSearcher.Create;
try
Searcher.OnFileFound:= @FileFoundEvent;
Searcher.DirectoryAttribute := faDirectory;
Searcher.Search(fPath, fFilter, true);
finally
Searcher.Free;
end;
fList.Sort;
end;
procedure TFileScannerThread.FileFoundEvent(FileIterator: TFileIterator);
var
s: string;
begin
s:= Copy(FileIterator.FileName, Length(fPath) + 1, MaxInt);
fList.Add(s);
end;
end.