I'd like to delete all files in a folder

brucesw

Active Member
Joined
Nov 12, 2002
Messages
301
Hello World,

I havd a folder "K:\UW\Reports\Credit report\" that contains about 60 workbooks. Each week I replace the folder contents with new reports, the number of reports vary each week. I don't want to leave old reports there so if a report is no longer needed the DisplayAlerts=False code won't cut it.

I had a look at help but cannot figure out the correct code. I guess the old DOS equivalent would be "del K:\UW\Reports\Credit report\*.*" or similar.

Can you help? Thanks in advance,

Bruce
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
To do this is an irreversible act, so make absolutely sure that's what you want. Hans Herber wrote this one, it's on the 1900 examples CD being marketed through this site.

Enter the path in cell B1 and run this:

Sub DeleteFiles()
Dim sPath As String
Dim iCounter As Integer
sPath = Range("B1").Value
If MsgBox("Do you really want to delete the files?", _
vbCritical + vbYesNo) = vbNo Then Exit Sub
With Application.FileSearch
.LookIn = sPath
.Filename = "*.xls"
.Execute
For iCounter = 1 To .FoundFiles.Count
Kill .FoundFiles(iCounter)
Next iCounter
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,444
Messages
6,130,659
Members
449,585
Latest member
Nattarinee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top