Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Posts
    15

    Unanswered: Using VBA to delete all files and subfolders in a parent directory

    I would like to write code that erases a folder as well as several levels of subfolders--in addition to killing all files in all subfolders.

    I have searched this and other forums to no avail.

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    The "scripting.FileSystemObject" will do what you need. There are a whole bunch of tutorials on using it once you know to search for "FileSystemObject".
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    To expand on Teddy's correctomundo suggestion (though Izy might pipe up about the equivalent VBA functions) you will also need to make this a recursive procedure. Not really sure why you cannot delete a populated folder. Perhaps someone in the know can enlighten....
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Jan 2005
    Posts
    15
    Thank you much for the feedback. I was able to solve this problem using fairly straightforward code. In case anyone encounters the same issue, here's the code:

    Public Sub Wipedir(dir As String)
    Dim filesys
    Set filesys = CreateObject("Scripting.FileSystemObject")
    If filesys.folderexists(dir) Then
    filesys.deletefolder dir
    Else
    End
    End If

    End Sub

  5. #5
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7

    Scrdoc56en.exe

    This is the help files for vbscripting

    It has some bloodly good code for createing/delete folder/files
    Attached Files Attached Files
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

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