Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to delete a file permanently? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Feb-04
Category
Files Operation
Language
Delphi All Versions
Views
197
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Yovanny Rodriguez

How to delete a file permanently?

Answer:

If you want to get rid of a file normally you just delete it. But someone else can 
undelete it if the file hasn't been wiped correctly. For security purposes, to 
insure that certain files are permanently gone, the WipeFile procedure writes over 
the data in the file with random characters and then erases it. 

1   procedure WipeFile(FileName: string);
2   var
3     buffer: array[0..4095] of Byte;
4     max, n: LongInt;
5     i: Integer;
6     fs: TFileStream;
7   
8     procedure RandomizeBuffer;
9     var
10      i: Integer;
11    begin
12      for i := Low(buffer) to High(buffer) do
13        buffer[i] := Random(256);
14    end;
15  begin
16    fs := TFilestream.Create(FileName, fmOpenReadWrite or fmShareExclusive);
17    try
18      for i := 1 to 3 do
19      begin
20        RandomizeBuffer;
21        max := fs.Size;
22        fs.Position := 0;
23        while max > 0 do
24        begin
25          if max > SizeOf(buffer) then
26            n := SizeOf(buffer)
27          else
28            n := max;
29          fs.write(Buffer, n);
30          max := max - n;
31        end;
32        FlushFileBuffers(fs.Handle);
33      end;
34    finally
35      fs.Free;
36    end;
37    Deletefile(FileName);
38  end; 



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC