Deleting files in a directory
On Jun 7, 3:15 pm, Sam wrote:
I have a process that creates csv files in a directory, however a byproduct
is an identical log file, e.g. 5C015000. If you were to rename the file with
a .xls extension, it would be exactly the same as the csv that I'm saving. It
has no extension and is file type "File".
If the directory were C:\GLPVC\ what code can I use to loop through all
files in the directory (there may be hundreds) and delete all files that
begin with a numeric character or whose file type is "File"?
Here try this...
Function DeleteFiles(MyWildcard As String) As Long
Dim Match
Match = Dir(MyWildcard)
If Len(Match) 0 Then
Do
MsgBox Match
Match = Dir
Loop Until Len(Match) = 0
End If
End Function
You will call it with a line that looks like...
Call DeleteFiles("C:\My Docs\*.*")
Now, instead of the line that reads...
MsgBox Match
....put a line that reads...
Kill Match
You would effectively be going through the folder one file at a time
and looking for a file size greater than 0. Any that match this
criteria get the ax. You can further make this dynamic by adding rules
to this code...
|