Results 1 to 15 of 15

Thread: delete a file? what's the syntax..

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    Cool

    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

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Code:
    Kill(Filename As String)

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    Lightbulb When did VB get this violent??

    That's it, thanx

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Guest
    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")

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Matthew, why would you overwrite it one time. I thought a file is only secure deleted when it's 5 times overwritten.

  7. #7
    Guest
    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.

  8. #8
    Guest
    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

  9. #9
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Is there any point to over-write all data in the file before deleting?

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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 refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    Lightbulb That *ROX*

    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

  12. #12
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    Oetje's allmost right

    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.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  13. #13
    Guest
    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.

  14. #14
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  15. #15
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you could also open it for output then delete it

    i.e
    Code:
    Open "c:\tobdeleted.enc" For Output As #1
    Write #1, ""
    Close #1
    Kill "c:\tobdeleted.enc"
    i think it would work

    but just kill is the easiest method

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width