Tools Links Login

*** Destroy a file without getting error! ***

This DOES use the kill function, but when you use this it actually opens the file you want to destroy, cleans it out, then deletes it so you don't get any error because of sensitive data!

Original Author: Matt Evans

Inputs

File To Delete

Assumptions

Make sure not to delete win.com, win.ini, config.sys, himem.sys, autoexec.bat or any of those files, lol ;D

Returns

No more file

Code

Sub DestroyFile(sFileName As String)
  Dim Block1 As String, Block2 As String, Blocks As Long
  Dim hFileHandle As Integer, iLoop As Long, offset As Long
  'Create two buffers with a specified 'wipe-out' characters
  Const BLOCKSIZE = 4096
  Block1 = String(BLOCKSIZE, "X")
  Block2 = String(BLOCKSIZE, " ")
  'Overwrite the file contents with the wipe-out characters
  hFileHandle = FreeFile
  Open sFileName For Binary As hFileHandle
    Blocks = (LOF(hFileHandle) BLOCKSIZE) + 1
    For iLoop = 1 To Blocks
      offset = Seek(hFileHandle)
      Put hFileHandle, , Block1
      Put hFileHandle, offset, Block2
    Next iLoop
  Close hFileHandle
  'Now you can delete the file, which contains no sensitive data
  Kill sFileName
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 130 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.