forked from martok/ImageHash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuThreadScanner.pas
More file actions
76 lines (64 loc) · 1.52 KB
/
uThreadScanner.pas
File metadata and controls
76 lines (64 loc) · 1.52 KB
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
71
72
73
74
75
unit uThreadScanner;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, uFileSearcher;
type
TFileScannerThread = class(TThread)
private
fPath: string;
fFilter: string;
fList: TStringList;
fSubDirs: boolean;
protected
procedure Execute; override;
procedure FileFoundEvent(FileIterator: TMyFileIterator);
public
constructor Create;
destructor Destroy; override;
property Path: string read fPath write fPath;
property Filter: string read fFilter write fFilter;
property SubDirs: boolean read fSubDirs write fSubDirs;
property List: TStringList read fList;
end;
implementation
{ TFileScannerThread }
constructor TFileScannerThread.Create;
begin
inherited Create(true);
FreeOnTerminate:= false;
fPath:= '';
fSubDirs:= true;
fFilter:= '*.*';
fList:= TStringList.Create;
end;
destructor TFileScannerThread.Destroy;
begin
FreeAndNil(fList);
inherited Destroy;
end;
procedure TFileScannerThread.Execute;
var
Searcher: TMyFileSearcher;
begin
fPath:= IncludeTrailingPathDelimiter(fPath);
Searcher := TMyFileSearcher.Create;
try
Searcher.OnFileFound:= @FileFoundEvent;
Searcher.DirectoryAttribute := faDirectory;
Searcher.SearchMask:= fFilter;
Searcher.SearchSubDirs:= fSubDirs;
Searcher.Search(fPath);
finally
Searcher.Free;
end;
fList.Sort;
end;
procedure TFileScannerThread.FileFoundEvent(FileIterator: TMyFileIterator);
var
s: string;
begin
s:= Copy(FileIterator.FileName, Length(fPath) + 1, MaxInt);
fList.Add(s);
end;
end.