ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete all files except... (https://www.excelbanter.com/excel-programming/388056-delete-all-files-except.html)

David Johnston[_2_]

Delete all files except...
 
I would like to make a little button that, wehn pressed, would delete
all files in a directory except for the ones that I specidy. It would
be nice if I could display a listbox and check the ones that I wanted
to delete but for now, I can just hardcode the files to keep. I can
populate the listbox but can't figure out how to delete the ones not
selected.

Anyone have any ideas on how to do this?
Thanks in advance,
David


Bernie Deitrick

Delete all files except...
 
David,

It would
be nice if I could display a listbox and check the ones that I wanted
to delete


Here's a macro that will delete the files that you choose:

Sub DeleteMultipleUserSelectedFiles()
Dim FileArray As Variant
Dim i As Integer

FileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(FileArray) Then
For i = LBound(FileArray) To UBound(FileArray)
Kill FileArray(i)
Next i
End If
End Sub

HTH,
Bernie
MS Excel MVP


"David Johnston" wrote in message
oups.com...
I would like to make a little button that, wehn pressed, would delete
all files in a directory except for the ones that I specidy. It would
be nice if I could display a listbox and check the ones that I wanted
to delete but for now, I can just hardcode the files to keep. I can
populate the listbox but can't figure out how to delete the ones not
selected.

Anyone have any ideas on how to do this?
Thanks in advance,
David





All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com