Script for clearing Chrome or Firefox cache on Windows


With Internet Explorer you can create a .bat file to clear the cache.

Example:

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

REM History:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

REM Cookies:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

REM Temp Internet Files:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

REM Form Data:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

REM Passwords:
REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

REM OR

REM All:
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

Is there any way to do this with Chrome and/or Firefox ?

That is, with a .bat file or powershell script, running on a Windows machine, clear the cache of Chrome or Firefox?

I promise, I've looked.


Answers:


In Chrome, you can clear the cache by deleting the contents of the Cache folder in %LocalAppData%\Google\Chrome\User Data\Default\Cache. The history, cookies, and so on are SQLite database files in the parent folder, so you could get rid of them too if you wanted everything gone, like in your example with Internet Explorer:

$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            'Login Data',
            'Top Sites',
            'Visited Links',
            'Web Data')
$Folder = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default"
$Items | % { 
    if (Test-Path "$Folder\$_") {
        Remove-Item "$Folder\$_" 
    }
}