This is what I have come up with the problem with the code is that it wont go into the sub folders to delete the files with the extensions
Dim fso, counter, sroot, objFSO, x
Dim fld, fls, oFile, dt, oFolder, strWildcardsToDelete
set fso = CreateObject("Scripting.FileSystemObject")
counter = 0
sroot = "C:\test\"
strWildcardsToDelete = "*.txt,*.mp3"
call deleteFile(sroot, strwildcardstodelete)
msgbox(counter)
sub deleteFile(StartPath, strwildcards)
Set fld = fso.getFolder(Startpath)
Set Fls = Fld.Files
Set objFSO = CreateObject("Scripting.FileSystemObject")
for Each oFile in Fls
on error resume next
if err.number=0 then
aExtensions = split(strWildcards, ",")
For i = LBound(aExtensions) to UBound(aExtensions)
'Delete the file
counter = counter + 1
objFSO.DeleteFile(startpath & aExtensions(i))
Next
else
'do something if necessary
err.clear
end if
on error goto 0
for each ofolder in Fld.subfolders
call deleteFile(ofolder.path, x)
msgbox "IM here"
next
next
end sub
i used the VAR X just as a decoy so i dont get the error "not enough parameters"
Thanks for any help
Dim fso, counter, sroot, objFSO, x
Dim fld, fls, oFile, dt, oFolder, strWildcardsToDelete
set fso = CreateObject("Scripting.FileSystemObject")
counter = 0
sroot = "C:\test\"
strWildcardsToDelete = "*.txt,*.mp3"
call deleteFile(sroot, strwildcardstodelete)
msgbox(counter)
sub deleteFile(StartPath, strwildcards)
Set fld = fso.getFolder(Startpath)
Set Fls = Fld.Files
Set objFSO = CreateObject("Scripting.FileSystemObject")
for Each oFile in Fls
on error resume next
if err.number=0 then
aExtensions = split(strWildcards, ",")
For i = LBound(aExtensions) to UBound(aExtensions)
'Delete the file
counter = counter + 1
objFSO.DeleteFile(startpath & aExtensions(i))
Next
else
'do something if necessary
err.clear
end if
on error goto 0
for each ofolder in Fld.subfolders
call deleteFile(ofolder.path, x)
msgbox "IM here"
next
next
end sub
i used the VAR X just as a decoy so i dont get the error "not enough parameters"
Thanks for any help