whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

51 Visitors Online


 
...delete a file permanently?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (11):  
     


{
  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.

  Wenn man eine Datei nicht mehr braucht, löscht man sie einfach.
  Aber jemand anders kann die Datei wieder herstellen, wenn sie
  nicht "richtig" gelöscht wurde.
  Aus Sicherheitsgründen, um sicherzustellen, dass eine Datei permanent
  gelöscht wird, überschreibt die WipeFile Prozedur eine Datei mit
  Zufalls-Zeichen und löscht sie anschliessend.
}

procedure WipeFile(FileName: string);
var
  
buffer: array [0..4095] of Byte;
  max, n: LongInt;
  i: Integer;
  fs: TFileStream;

  procedure RandomizeBuffer;
  var
    
i: Integer;
  begin
    for 
i := Low(buffer) to High(buffer) do
      
buffer[i] := Random(256);
  end;
begin
  
fs := TFilestream.Create(FileName, fmOpenReadWrite or fmShareExclusive);
  try
    for 
i := 1 to do
    begin
      
RandomizeBuffer;
      max := fs.Size;
      fs.Position := 0;
      while max > 0 do
      begin
        if 
max > SizeOf(buffer) then
          
n := SizeOf(buffer)
        else
          
n := max;
        fs.Write(Buffer, n);
        max := max - n;
      end;
      FlushFileBuffers(fs.Handle);
    end;
  finally
    
fs.Free;
  end;
  Deletefile(FileName);
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners