Showing posts with label vbscript to delete files. Show all posts
Showing posts with label vbscript to delete files. Show all posts
Thursday, 21 June 2012
Delete Files of common name - VBScript
Suppose cr123.tmp, crequ.tmp, crkkin.tmp...........etc files are present under C:\Windows folder
The following script can be used to delete cr*.tmp files from C:\Windows folder
strDir = "C:\WINDOWS"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
If (LCase(Left(Cstr(aItem.Name), 2)) = "cr") AND fso.GetExtensionName(LCase(aItem.Name)) = "tmp" Then
aItem.delete(True)
End If
Next
For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next
End Sub
Subscribe to:
Posts (Atom)