📜 VBScript (WSH)
Clean Up Google Chrome's browser cache (VBScript)
Reports the size of Google Chrome's browser cache and deletes its contents after a confirmation prompt.
CleanChromeCache.vbs
' ============================================================
' CleanChromeCache.vbs
'
' Reports the size of Google Chrome's browser cache, then deletes its contents after
' confirmation.
'
' Usage: cscript CleanChromeCache.vbs
' ============================================================
Option Explicit
Dim objFSO, objShell, objFolder, objFile, objSubFolder
Dim targetPath, totalSize, fileCount, confirm
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
targetPath = objShell.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\Google\Chrome\User Data\Default\Cache"
If Not objFSO.FolderExists(targetPath) Then
WScript.Echo targetPath & " does not exist on this machine."
WScript.Quit
End If
Set objFolder = objFSO.GetFolder(targetPath)
totalSize = 0
fileCount = 0
On Error Resume Next
For Each objFile In objFolder.Files
totalSize = totalSize + objFile.Size
fileCount = fileCount + 1
Next
On Error Goto 0
WScript.Echo targetPath & " contains " & fileCount & " file(s), " & _
Round(totalSize / 1024 / 1024, 2) & " MB"
confirm = MsgBox("Delete the contents of " & targetPath & "?", vbYesNo + vbQuestion, "Confirm cleanup")
If confirm = vbYes Then
On Error Resume Next
For Each objFile In objFolder.Files
objFile.Delete True
Next
For Each objSubFolder In objFolder.SubFolders
objSubFolder.Delete True
Next
On Error Goto 0
WScript.Echo "Cleanup complete."
Else
WScript.Echo "Cancelled."
End If