Tuesday, July 8, 2008
Delete temporary files easily and quickly
Labels: batch, delete, empty, temp, temporary, vbs 0 commentsIn order to delete temporary files on a Windows machine, there are many quick CLI commands, such as rmdir "%temp%". Depending on the size of the %temp% folder though, this command can take a bit to run. If you place it into a login script, you'll end up delaying a user's login while their temp folder is being cleaned.
To reduce the time needed for deleting temporary files, I suggest using a vbscript instead.
Copy the following and save it into a .vbs file such as 'cleantemp.vbs'. When you run it, it will erase all files inside your temp folder quickly and silently.
'This script deletes all files not in use in the 'target folder' (change line 8 to select something other than temp)♦DiggIt! ♦Add to del.icio.us ♦Add to Technorati Faves
Option Explicit
On Error Resume Next
Dim target, objShell, strEnv, newfso, fso, objFiles, strFile, oSubfolder
Set objShell = CreateObject("Wscript.Shell")
target = objShell.ExpandEnvironmentStrings("%temp%")
Set fso = CreateObject("Scripting.FileSystemObject")
Set newfso = fso.GetFolder(target)
Set objFiles = newfso.Files
For each strFile in objFiles
strFile.delete
next
For Each oSubFolder In newfso.SubFolders
fso.DeleteFolder oSubFolder
Next
0 comments: to “ Delete temporary files easily and quickly ”
Post a Comment