+ Reply to Thread
Results 1 to 4 of 4

Delete an entire folders contents (or just Excel files)

  1. #1
    Registered User
    Join Date
    04-25-2005
    Posts
    99

    Delete an entire folders contents (or just Excel files)

    Is it possible to delete the entire contents of a folder with the VBA? I'd like to be able to delete either all of the files out of a folder or delete all the Excel files out of a folder. I know I can use
    Please Login or Register  to view this content.
    I assume that I can use some sort of loop to find all the files in a folder and delete them, but is it possible to Kill an entire folder's contents???

    TIA
    DejaVu

  2. #2
    Martin Krastev
    Guest

    RE: Delete an entire folders contents (or just Excel files)

    Use the FileSearch Object.
    The following is from VBA help:

    With Application.FileSearch
    If .Execute() > 0 Then
    MsgBox "There were " & .FoundFiles.Count & _
    " file(s) found."
    For i = 1 To .FoundFiles.Count
    kill .FoundFiles(i)
    Next i
    Else
    MsgBox "There were no files found."
    End If
    End With


    "DejaVu" wrote:

    >
    > Is it possible to delete the entire contents of a folder with the VBA?
    > I'd like to be able to delete either all of the files out of a folder
    > or delete all the Excel files out of a folder. I know I can use
    > Code:
    > --------------------
    > Kill "C:\Test Folder\TestBk.xls"
    > --------------------
    >
    >
    > I assume that I can use some sort of loop to find all the files in a
    > folder and delete them, but is it possible to Kill an entire folder's
    > contents???
    >
    > TIA
    > DejaVu
    >
    >
    > --
    > DejaVu
    > ------------------------------------------------------------------------
    > DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
    > View this thread: http://www.excelforum.com/showthread...hreadid=531060
    >
    >


  3. #3
    Ron de Bruin
    Guest

    Re: Delete an entire folders contents (or just Excel files)

    You can use this to delete all the files in the folder

    Kill "C:\Test Folder\*.*"

    Or xls files

    Kill "C:\Test Folder\*.xls"

    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "DejaVu" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Is it possible to delete the entire contents of a folder with the VBA?
    > I'd like to be able to delete either all of the files out of a folder
    > or delete all the Excel files out of a folder. I know I can use
    > Code:
    > --------------------
    > Kill "C:\Test Folder\TestBk.xls"
    > --------------------
    >
    >
    > I assume that I can use some sort of loop to find all the files in a
    > folder and delete them, but is it possible to Kill an entire folder's
    > contents???
    >
    > TIA
    > DejaVu
    >
    >
    > --
    > DejaVu
    > ------------------------------------------------------------------------
    > DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
    > View this thread: http://www.excelforum.com/showthread...hreadid=531060
    >




  4. #4
    Registered User
    Join Date
    04-25-2005
    Posts
    99
    Thank you both for the quick response. Both solutions appear to accomplish the task I was looking for. Ron de Bruin - I thought it might be easier than what I was putting into it, but I had no idea it would be one line!! Thanks again.

    DejaVu

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1