Results 1 to 6 of 6

Thread: How do I delete Files using VB?

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Question

    How do you delete files using VB???

    Thanx for any help!!
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    you use the kill statement ... like:

    kill "c:\filename.exe"

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Thanx

    Thats what I was trying but I had one slight problem:

    I did this:
    Code:
    Msgbox FileSystem.Kill ("C:\Temp123456789.txt")
    I thought it was a boolean function which would say if it worked or if it failed.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    If it didn't work it will return an error.
    You would have to do something like this:
    Code:
    On Error Goto ErrHandle
    Kill ("C:\Temp123456789.txt")
    Exit Sub
    ErrHandle:
       Msgbox "There was an error."

  5. #5
    Guest
    This thread may be of interest to you as well.

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    API?

    You can also use the API to get some extra effects....

    Code:
    Private Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As Long
    End Type
    
    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    
    Private Const FO_DELETE = &H3
    Private Const FOF_ALLOWUNDO = &H40 ' if this flag included files will be sent to the recycling bin
    Private Const FOF_SILENT = &H4 ' if this flag is included then the progress screen will not be displayed
    Private Const FOF_NOCONFIRMATION = &H10 ' if this flag is included then the user will not be asked to confirm the files to be deleted
    
    Public Sub cmdDelete_Click()
     Dim lRet As Long
     Dim fFileStruct As SHFILEOPSTRUCT
        
       With fFileStruct
         .wFunc = FO_DELETE
         ' You can also delete multiple files by passing a string variable in this format "C:\Windows\text.txt" & vbNullChar & "C:\Windows\text2.txt"
         .pFrom = "C:\Windows\Text.txt"
         'Include next line of code if you want to send files to the recycling bin
         '.fFlags = .fFlags Or FOF_ALLOWUNDO 
         'Include the next line of code if you do not want the progress of the files being deleted
         '.fFlags = .fFlags Or FOF_SILENT
         'Include the next line of code if you want a screen that says "Are you sure you want to delete this file" to come up
         '.fFlags = .fFlags Or FOF_NOCONFIRMATION
       End With
        
        lRet = SHFileOperation(fFileStruct)
    
        if lRet = 0 then 
           MsgBox "File(s) not deleted"
        end if
    
    End Sub
    Also a MessageBox will be automatically displayed if you try to delete a file that is currently in use.

    [Edited by YoungBuck on 11-25-2000 at 05:29 PM]
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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