Delete All Files from a Folder

  • From an active worksheet, I need to delete all files from folder c:\Trials\Current\ before writing new files to that folder. I've searched for existing examples but everything I can find seems to relate to earlier versions of Excel and gives compile errors whenever I run the code.

    Can someone please suggest coding that will delete all the files and that will function with Excel 2013.

  • Re: Delete All Files from a Folder

    Hi OldFella,

    Try this:

    Maybe worth trying it first on a copy of your directory as the results cannot be undone if they're not as expected.



  • Re: Delete All Files from a Folder

    Thanks Robert.

    Your code, in many ways, looks similar to the code I've been trying. The difference is that my code didn't work and yours works like a charm. It helps solve a problem I previously didn't realise I had and this will be the major part of the solution.

    Your help is really appreciated.

  • Re: Delete All Files from a Folder

    Thanks apo - that's different! I'm working off my laptop at present so can't trial your code. I'll be home tomorrow so I'll crank the desktop up then and give it a whirl. Many thanks for the interest.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!