FilesKill

Delete Multiple Files (with WildCards)
To delete multiple files from a directory based on a string pattern eg. "C:\temp\*.tmp"
' Needs : GetPaPa or function 'PathFileToPath' saved below


Public

Not Tested

Not My Work
' Purpose : Delete single or multiple files, based on the sFileName criteria
' Outputs : Returns True if errors where encountered
Function FilesKill(sFileName As String, Optional bDeleteReadOnly As Boolean) As Boolean
 Dim sThisFile As String, sThisPath As String
 On Error Resume Next
 If InStr(1, sFileName, "*") > 0 Or InStr(1, sFileName, "$") > 0 Then
  ' Kill multiple files
  sThisPath = GetPaPa(sFileName)
  sThisFile = Dir(sFileName, vbNormal)
  Do While Len(sThisFile)
   If bDeleteReadOnly Then
    SetAttr sThisPath & sThisFile, vbNormal
   End If
   Kill sThisPath & sThisFile
   sThisFile = Dir
  Loop
 Else
  If bDeleteReadOnly Then
   SetAttr sFileName, vbNormal
  End If
  Kill sFileName
 End If
 FilesKill = (Err.Number <> 0)
 On Error GoTo 0
End Function

sFileName The full path and name of a file (can include either * or $)
[bDeleteReadOnly] If True, routine will delete readonly files too

Views 799 Downloads 209

VBA File System
ANmarAmdeen
660
Attachments
Revisions

v2.0

Needs