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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try...

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

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,458
Members
449,161
Latest member
NHOJ

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