Using Kill and "*.*" to delete all files in a folder

cfdh_edmundo

Board Regular
Joined
Nov 9, 2005
Messages
133
Hi,

I have a line of code as follows:

Code:
Kill tempPath & "*.*"

which works exactly as I want. I deletes all files in a temporary folder before running the rest of the macro.

The problem I have is when there are no files in the directory (i.e. it's an empty directory) then I get a "Run-time error '53': File not found" error.

Is there a neat way to put some simple error handling so the macro will just skip the line if there directory is empty?

Many thanks for any help,

Chris
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try...

Code:
On Error Resume Next
Kill tempPath & "*.*"
On Error GoTo 0

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,746
Members
453,370
Latest member
juliewar

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