彻底删除文件(Delphi源码)

更新时间:2023-10-13 08:49:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

彻底删除文件源码

unit Unit1;

interface uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls; type

TForm1 = class(TForm) Button1: TButton;

OpenDialog1: TOpenDialog; Button2: TButton; Edit1: TEdit;

ProgressBar1: TProgressBar; Button3: TButton; Button4: TButton; Timer1: TTimer; Button5: TButton;

procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private

{ Private declarations } public

{ Public declarations } end; var

Form1: TForm1; FileName:String;

implementation

{$R *.dfm}

Procedure DelOne(FileName:String); var

f: file of byte; n: byte; i:integer;

SizeInt:Int64; begin

AssignFile(f, FileName); Reset(f);

SizeInt:=FileSize(f); n := 0;

for i := 1 to SizeInt do begin

BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure DelTwo(FileName:String); var

f: file of byte; n: byte; i:integer; begin

AssignFile(f, FileName); Reset(f); n := 1;

for i := 1 to FileSize(f) do begin

BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure DelThree(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(3); BlockWrite(f, n, 1); end;

CloseFile(f);

end;

Procedure DelFour(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(4); BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure Delfive(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(5); BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure Delsix(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName);

Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(6); BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure Delsven(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(7); BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure DelEt(FileName:String); var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(8); BlockWrite(f, n, 1); end;

CloseFile(f); end;

Procedure DelNine(FileName:String);

var

f: file of byte; n: byte; i:integer; begin

Randomize;

AssignFile(f, FileName); Reset(f);

for i := 1 to FileSize(f) do begin

n :=Random(9); BlockWrite(f, n, 1); end;

CloseFile(f); end;

procedure TForm1.Button1Click(Sender: TObject); begin

DelOne(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelTwo(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelThree(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelFour(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; Delfive(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelSix(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; Delsven(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelEt(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelNine(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DeleteFile(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; ShowMessage('OK'); end;

procedure TForm1.Button2Click(Sender: TObject); begin

if OpenDialog1.Execute then

Edit1.Text:=OpenDialog1.FileName; end;

procedure TForm1.Timer1Timer(Sender: TObject); begin

DelOne(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelTwo(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelThree(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelFour(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; Delfive(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelSix(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; Delsven(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelEt(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DelNine(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; DeleteFile(Edit1.Text);

ProgressBar1.Position:=ProgressBar1.Position+1; ShowMessage('OK'); Timer1.Enabled:=False; end;

procedure TForm1.Button3Click(Sender: TObject); begin

Timer1.Enabled:=True; end;

procedure TForm1.Button4Click(Sender: TObject); begin

Timer1.Enabled:=False; end; end.

本文来源:https://www.bwwdw.com/article/3s4f.html

Top