I thought it was Remove(filename)
but i guess not, I don't have any VB help files on my comp so if someone could enlighten me I'd be a happy camper ;)
-Brad
Printable View
I thought it was Remove(filename)
but i guess not, I don't have any VB help files on my comp so if someone could enlighten me I'd be a happy camper ;)
-Brad
Code:Kill(Filename As String)
That's it, thanx
It's a good idea to check for the file's existance
since you will generate an error if the file isn't found
Code:
'does file exist using fso
Dim sFile$
sFile = "Name And Path Of Your File"
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(sFile$) = True Then
MsgBox "File Exists...Your code here!"
Else
MsgBox "Does Not Exist...Your code here!"
End If
Set fs = Nothing
You could also use this code and erase all the contents in a file and then delete it.
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
Usage:
Call DestroyFile("C:\program.exe")
Matthew, why would you overwrite it one time. I thought a file is only secure deleted when it's 5 times overwritten.
No need. That code erases all the contents in the file. Than simply uses the Kill function to remove it.
See for yourself, remove the Kill sFileName and then open the file in Edit and you will see the file has been wiped out completely.
So if you were to do it 5 times, it would not make a difference than if you did it once.
You can also the Dir() function, you can check if the file exsists or not.
Code:If Dir$("MyfileName") <> "" Then
'File exsists
Else
'File Does not exsist
End If
Is there any point to over-write all data in the file before deleting?
If you just delete it, all it does is mark the file's clusters as free. The contents of the file will still be on the disk. In a secure environment, you will not want this.
I thought I would have to empty the recycle bin after deleting
Wiping out the whole file *first* is definetely a plus.
I'm going to be having sensitive data in an encrypted file. After I decrypt it and write the normal file to access vars from I simply encrypt again and delete the unencrypted file.
Wiping out the whole thing in one shot will definetely put me more at ease, thanx man!
and to think... I was just going to 'Kill' it...
heh
-Brad
Matthew, I read that a file is really secure deleted when it's 7, yes 7 times overwritten, don't ask me why, but it's true according to a Danish File Securing company which rescues lost data.
Really? 7 times? That's a lot. But to the point, if you tried that code, it has erased everything inside the file. So even if you were to retrieve it with a file restorer (or whatever they're called), you'll have the file, but nothing in it. It will be a totally useless file. If you just use the Kill function to remove the file, you could probably restore it and be able to use the file again.
Yeah I couldn't believe that neither.
Dunno why, but it's considered DELETED with no chance of *ever* backuping it when it's overwritten 7 times or something
you could also open it for output then delete it
i.e
i think it would work :)Code:Open "c:\tobdeleted.enc" For Output As #1
Write #1, ""
Close #1
Kill "c:\tobdeleted.enc"
but just kill is the easiest method