home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
chap30
/
delallw
/
main.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-03-20
|
5KB
|
182 lines
unit Main;
{ Contents copyright (c) 1995 by Charles Calvert }
{ Project Name: DELALLW }
interface
uses
SysUtils, WinTypes, WinProcs,
Messages, Classes, Graphics,
Controls, Forms, Dialogs,
StdCtrls, AllDirs, Fileiter,
Menus, Buttons, ExtCtrls,
FileCtrl;
type
TForm1 = class(TForm)
FileIterator1: TFileIterator;
MainMenu1: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
DeleteBtn: TBitBtn;
Panel1: TPanel;
ExtBox: TListBox;
BitBtn2: TBitBtn;
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
OpenDelFile1: TMenuItem;
Panel2: TPanel;
DelExe: TCheckBox;
DelTilda: TCheckBox;
OpenDirSizeFile1: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure DeleteBtnClick(Sender: TObject);
procedure DriveComboBox1Change(Sender: TObject);
procedure FileIterator1FoundFile(FileName: String; SR: TSearchRec);
procedure FileIterator1ProcessDir(DirName: String);
private
StartPath: string;
FDelTilda: Boolean;
FDelExes: Boolean;
FDeleteList: TStringList;
FDirSizeList: TStringList;
FDirName: string;
FDirSize: LongInt;
FDirSizeName: string;
FDelListName: string;
FExtBoxName: string;
function LoadExtBox: Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
StrBox,
UtilBox;
{$R *.DFM}
function TForm1.LoadExtBox: Boolean;
begin
ExtBox.Items.LoadFromFile(FExtBoxName);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ExtBox.Items.SaveToFile(FExtBoxName);
FDeleteList.Free;
FDirSizeList.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDeleteList := TStringList.Create;
FDirSizeList := TStringList.Create;
StartPath := StripLastToken(ParamStr(0), '\');
FDirSizeName := StartPath + '\dirsize.txt';
FDelListName := StartPath + '\dellist.txt';
FExtBoxName := StartPath + '\extbox.txt';
LoadExtBox;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Open1Click(Sender: TObject);
var
SPtr: array[0..150] of char;
S: string;
begin
case TMenuItem(Sender).Tag of
100: S := FExtBoxName;
101: S := FDelListName;
102: S := FDirSizeName;
end;
StrPCopy(SPtr, 'notepad.exe ' + S);
WinExecAndWait(SPtr, sw_ShowNormal);
LoadExtBox;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.DeleteBtnClick(Sender: TObject);
var
i: Integer;
S: string;
begin
Cursor := crHourGlass;
FDelTilda := DelTilda.Checked;
FDelExes := DelExe.Checked;
s := DirectoryListBox1.Directory + '\';
if MessageDlg('Delete from: ' + S, mtConfirmation,
[mbYes, mbNo], 0) = idNo then Exit;
FileIterator1.Run('*.*', DirectoryListBox1.Directory);
FDeleteList.SaveToFile(FDelListName);
FDirSizeList.Add(FDirName + ': ' + IntToStr(FDirSize));
DeleteFile(FDirSizeName);
FDirSizeList.SaveToFile(FDirSizeName);
for i := 0 to FDeleteList.Count - 1 do
DeleteFile(FDeleteList.Strings[i]);
Cursor := crDefault;
end;
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DirectoryListBox1.Drive := DriveComboBox1.Drive;
DirectoryListBox1.Directory := '';
end;
procedure TForm1.FileIterator1FoundFile(FileName: String; SR: TSearchRec);
var
S: string;
i: Integer;
AddToDirSize: Boolean;
begin
AddToDirSize := False;
S := UpperCase(ExtractFileExt(FileName));
for i := 0 to ExtBox.Items.Count - 1 do begin
if (S = '.EXE') and (not FDelExes) then begin
AddToDirSize := True;
Continue;
end;
if S = UpperCase(ExtBox.Items.Strings[i]) then begin
FDeleteList.Add(FileName);
Continue;
end;
if not FDelTilda then
AddToDirSize := True
else if S[2] = '~' then begin
FDeleteList.Add(FileName);
Continue;
end;
AddToDirSize := True;
end;
if AddToDirSize then FDirSize := FDirSize + SR.Size;
end;
procedure TForm1.FileIterator1ProcessDir(DirName: String);
begin
FDirSizeList.Add(FDirName + ': ' + IntToStr(FDirSize));
FDirName := DirName;
FDirSize := 0;
end;
end.