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
' 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
' 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
[bDeleteReadOnly] If True, routine will delete readonly files too
Views 2,099
Downloads 650
CodeID
DB ID