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 88 89 90 91 92 93 94
|
unit Utreemapping;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
ComCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
SelectDirectoryDialog1: TSelectDirectoryDialog;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
function exploreDirectory(path : String) : Int64;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
Const FileFound = 0;
CharCR = Chr(13);
CharLF = Chr(10);
StringCRLF = CharCR + CharLF;
WildcardSearch = '\*.*';
{ TForm1 }
function TForm1.exploreDirectory(path : String) : Int64;
var
SearchResult : TSearchRec;
res : Int64;
begin
res := 0;
If FindFirstUTF8(path + WildcardSearch, faAnyFile, SearchResult) = FileFound then
begin
if Not ((SearchResult.Attr And faDirectory ) = 0) then
begin
if (trim(SearchResult.FindData.cFileName) <> '.') and (trim(SearchResult.FindData.cFileName) <> '..') then
begin
res := res + exploreDirectory(path + DirectorySeparator + SearchResult.Name );
end
end
else
begin
res := res + SearchResult.Size;
end;
While FindNextUTF8 (SearchResult) = FileFound Do
begin
if Not((SearchResult.Attr And faDirectory ) = 0 )then
begin
if (trim(SearchResult.FindData.cFileName) <> '.') and (trim(SearchResult.FindData.cFileName) <> '..') then
begin
res := res + exploreDirectory(path + DirectorySeparator + SearchResult.Name );
end;
end
else
begin
res := res + SearchResult.Size ;
end;
end;
end;
FindCloseUTF8(SearchResult);
Label2.Caption:= Label2.Caption + inttostr(res) + ';' + path + StringCRLF;
exploreDirectory := res;
end;
Procedure TForm1.Button1Click(Sender: TObject);
Begin
SelectDirectoryDialog1.Execute;
Label1.Caption := SelectDirectoryDialog1.FileName;
Label2.Caption := '';
Label2.Caption := 'Racine : ' + inttostr(exploreDirectory(SelectDirectoryDialog1.FileName)) +StringCRLF + Label2.Caption;
End;
end. |