Pages

Friday 16 January 2009

Delete files of common naming using 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

No comments:

Post a Comment