Link to home
Start Free TrialLog in
Avatar of developingprogrammer
developingprogrammer

asked on

delete all files from folder even if folder is blank

hey guys,

i'm using this code to delete all files from the folder

Kill CurrentProject.Path & "\Working Folder\*"

Open in new window


however when there are no files in the folder it gives me this error message

Run-time error '53':

File not found.


Question: what is the code i should use to delete all files in a folder, regardless if there are files or not?

Thoughts: i'm thinking just put a On Error Resume Next and an On Error Goto 0 but that would be an easy way out and we won't learn anything by taking easy ways during training = )

thanks guys!
SOLUTION
Avatar of regmigrant
regmigrant
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of developingprogrammer
developingprogrammer

ASKER

hi regmigrant, thanks for your help! i was thinking of using that line of code as i've used that before to test for files before writing to the network drive, but i guess i was looking for a one liner code (if it exists at all - which it doesn't now i've learnt ha = )   )

hi Christian!

yup i fully agree with you, i'm thinking that if there is a one liner code to test the folder then i'll use that, if not i'll use on error resume next because that is the most economical way of doing it and then i can use my time to focus on more productive development. thanks for confirming it and once again sharing more insight on the right mindset for programming, not just the technical code itself! = )