⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 Delphi 有很多很好的例子
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    Panel3: TPanel;
    Panel4: TPanel;
    DriveComboBox1: TDriveComboBox;
    Panel5: TPanel;
    DirectoryListBox1: TDirectoryListBox;
    procedure MakeTree;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  TreeCount, FilesCount, DirsCount : integer;
  TreeSize, FilesSize, DirsSize : longint;
implementation

uses Unit2;




{$R *.DFM}

procedure TForm1.MakeTree;
var  Sr : TSearchRec;
     Err : integer;
     TrSize, FilePath : string;
Begin
 Err:=FindFirst('*.*',$37,Sr) ;
 While (Err = 0) do
  begin
   if Sr.Name[1]<>'.' then
   begin
     FilePath:=ExpandFileName(Sr.Name);
     TreeSize:=TreeSize+Sr.Size;
     TrSize:=FloatToStr(TreeSize);
     Form1.Caption:=DirectoryListBox1.Directory+'  '+IntToStr(TreeCount)
                   +'  files and folders    Size: '+TrSize;
     if (Sr.Attr and faDirectory)=0 then
        begin
          FilesSize:=FilesSize+Sr.Size;
          inc(FilesCount);
        end;
     inc(TreeCount);
   end;
   If ((Sr.Attr and faDirectory)<>0)AND(Sr.Name[1] <> '.') then
   begin
     DirsSize:=DirsSize+Sr.Size;
     inc(DirsCount);
     ChDir(Sr.Name) ;
     MakeTree ;
     ChDir('..') ;
   end ;
   Err:=FindNext(Sr) ;
  end ;

End;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 TreeCount:=1;
 FilesCount:=0;
 DirsCount:=0;
 TreeSize:=0;
 FilesSize:=0;
 DirsSize:=0;
 ChDir(DirectoryListBox1.Directory);
 MakeTree;
 with form2 do
 begin
  edit1.text:=inttostr(DirsCount);
edit2.text:=inttostr(FilesCount);
edit3.text:=inttostr(FilesSize);
end;
form2.showmodal;
end;


procedure TForm1.FormResize(Sender: TObject);
begin
    BitBtn1.Left:=round((Form1.Width-BitBtn1.Width)/2)-5;
    DriveComboBox1.Left:=round((Form1.Width-DriveComboBox1.Width)/2-5);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -