VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Destroy a file without getting error

by Matt Evans (6 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

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!

Inputs
File To Delete
Assumes
Make sure not to delete win.com, win.ini, config.sys, himem.sys, autoexec.bat or any of those files, lol ;D
Code Returns
No more file

Rate Destroy a file without getting error

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

Download this snippet    Add to My Saved Code

Destroy a file without getting error Comments

No comments have been posted about Destroy a file without getting error. Why not be the first to post a comment about Destroy a file without getting error.

Post your comment

Subject:
Message:
0/1000 characters