This function will delete all files with a given extension in a specified
folder; e.g. Clean("C:\TEMP","xml") will delete any .xml files in the
C:\TEMP folder. It returns the number of files deleted and also (if you need
to check the file names) prints the files deleted in the debugger.
Public Function Clean(FolderPath As String, Extension As String) As Integer
Altering files in a Dir Loop can cause problems - or so sayeth the Knowledge
Base. I have never encountered any, but one never knows. In any event,
this can all be done in one line, so no use looping or using Dir.
Public Function Clean(FolderPath As String, Extension As String)
Kill FolderPath & "*." & Extension
End Sub
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.