Pages

Saturday, October 11, 2014

Delete Temp files using VB Script

Copy this code into a notepad and save it as .vbs file. It can be configured in scheduler so that it can be run on a regular basis and clear your system temp files or you can double click on the file on the need basis and it do the job.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set WShell            =   CreateObject("WScript.Shell")
sHost                =   WShell.ExpandEnvironmentStrings( "%USERNAME%" )
Set WShell            =   Nothing
Set oFSO            =   CreateObject("Scripting.FileSystemObject")
sTempPath            =   "C:\Users\"&sHost&"\AppData\Local\Temp"
Set oFolder        =   oFSO.getfolder(sTempPath)
Set oSubFoldersObj    =   oFolder.SubFolders
Set oFilesObj        =   oFolder.Files

Foreach oFile in oFilesObj
    OnErrorResumeNext
    oFile.Delete
    OnErrorGoto0
Next

Foreach oSubFol in oSubFoldersObj
    OnErrorResumeNext
    oSubFol.Delete
    OnErrorGoto0
Next

set oFolder        =   Nothing
Set oSubFoldersObj    =   Nothing
Set oFilesObj        =   Nothing`
Set oFSO            =   Nothing


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

No comments: