I need some code to securely delete a file.
I'd like some some opinions about the following code i wrote.
Code:Public Sub SecureDelete(ByRef FilePath As String, Optional ByRef Rewrites As Long = 7) Dim sFiller Dim lFileSize As Long Dim lR As Long Dim lFF As Long On Error Resume Next lFileSize = FileLen(FilePath) If lFileSize = 0 Then Kill FilePath Else lFF = FreeFile Open FilePath For Input As lFF For lR = 1 To Rewrites Do While Len(sFiller) < lFileSize sFiller = sFiller & CStr((64000 * Rnd)) DoEvents 'could take a while, don't lock the app Loop sFiller = Right$(sFiller, lFileSize) Print lFF, sFiller 'to save time, instead of re-writting the whole string, 'just shift it a a random length sFiller = Right$(sFiller, lFileSize - Int(500 * Rnd)) Next Close lFF End If Kill FilePath On Error GoTo 0 End Sub




Reply With Quote