aboutsummaryrefslogtreecommitdiff
path: root/Source/Filez.pas
blob: 8d959a4d6b00668ecca233a3956013412cd09dda (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
unit Filez;
{$I-}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  THandleFileEvent = procedure( const SearchRec:TSearchRec;
   const FullPath: String ) of object;
  // fullpath contains filepath+filename

  TScanDir = class(TComponent)
  private
    { Private declarations }
    FOnHandleFile : THandleFileEvent;
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure Scan( const Path : String );
    constructor Create( AOwner:TComponent ); override;
  published
    { Published declarations }
    property OnHandleFile : THandleFileEvent read FOnHandleFile write FOnHandleFile;
  end;

  function FileSizeByName( const FileName:String ):Longint;

procedure Register;

implementation

uses
  Strz;

function FileSizeByName( const FileName:String ):Longint;
var
  F:file of Byte;
begin
  Result := 0;
  AssignFile(F, FileName);
  Reset(F);
  if IoResult<>0 then Exit;
  Result := FileSize(F);
  Close(F);
end;

constructor TScanDir.Create( AOwner:TComponent );
begin
  inherited Create( AOwner );

  FOnHandleFile := nil;
end;

procedure TScanDir.Scan( const Path : String );
var
  SearchRec : TSearchRec;
  Result : Integer;
  S : String;
begin
  if not Assigned(FOnHandleFile) then
    Exit;

  S := VerifyBackSlash(Path);
  Result := FindFirst( S+'*.*', faAnyFile, SearchRec);
  if Result=0 then
    repeat
      if (SearchRec.Name='.') or (SearchRec.Name='..') then
        Continue;

      FOnHandleFile( SearchRec,
       S+SearchRec.Name );

      if SearchRec.Attr and faDirectory>0 then
        Scan( S+SearchRec.Name );
    until FindNext(SearchRec)<>0;
end;

procedure Register;
begin
  RegisterComponents('Labrz', [TScanDir]);
end;

end.