PDA

View Full Version : Loop Through And Delete Multiple File Types In A Folder



Excel Fox
03-30-2013, 04:47 PM
Sub LoopFolder()

Dim strFile As String
Dim strFileType As String
Dim strPath As String
Dim lngLoop As Long

strPath = "C:\ExcelFox"
strFileType = "*.jpeg;*.gif" 'Split with semi-colon if you want to specify the file types. Example ->> "*.xls;*.doc"

For lngLoop = LBound(Split(strFileType, ";")) To UBound(Split(strFileType, ";"))
strFile = Dir(strPath & "\" & Split(strFileType, ";")(lngLoop))
Do While strFile <> ""
Kill strFile
strFile = Dir
Loop
Next lngLoop

strFile = vbNullString
strFileType = vbNullString
strPath = vbNullString
lngLoop = Empty

End Sub