Results 1 to 7 of 7

Thread: How to delete the folder if the folder exist

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to delete the folder if the folder exist

    I would like to delete the folder if the folder exist.. How to do that?

    Code:
      Dim FSO As Object
        Set FSO = CreateObject("scripting.filesystemobject")
    KrigProjectPath = interpolProjWorkspace + "\" + TxtKrigRasterWorkspace.Text
    If FSO.FolderExists(KrigProjectPath) = True Then
         Exit Sub
    End If

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete the folder if the folder exist

    Code:
    If Dir$("c:\hack", vbDirectory) <> vbNullString Then
       Kill ("c:\hack\*.*")
       RmDir ("c:\hack")
    Else
       MsgBox "directory does not exist"
    End If

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to delete the folder if the folder exist

    How to delete all files in the folder?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete the folder if the folder exist

    I posted an example of that.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to delete the folder if the folder exist

    Kill ("c:\hack\*.*")
    RmDir ("c:\hack")


    Which one that delete the folder and delete the files?

  6. #6
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to delete the folder if the folder exist

    if your using FSO, then do it like this. I just did the same thing today ,

    Code:
    Dim oFolder As scripting.Folder
    Dim oFile As scripting.File
    Dim fso As scripting.FileSystemObject
    Code:
    Set fso = New FileSystemObject
    
    
    If fso.FolderExists("c:\temp\EmailAttachments") Then
         Set oFolder = fso.GetFolder("c:\temp\EmailAttachments")
        On Error Resume Next
        For Each oFile In oFolder.Files
            oFile.Delete True  'setting force to true
                            'deletes read-only file
        Next
    endif
    to delete folder use same principle with:

    Code:
    ofolder.delete
    Last edited by Nitesh; Apr 1st, 2008 at 08:13 AM. Reason: adding info

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to delete the folder if the folder exist

    Quote Originally Posted by matrik02
    Kill ("c:\hack\*.*")
    RmDir ("c:\hack")


    Which one that delete the folder and delete the files?
    Kill deletes the files. RmDir Removes the Directory.

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