Script to clear the cache of Chrome or Firefox on Windows

With Internet Explorer you can create a file .bat

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 a way to do this using Chrome and / or Firefox?

That is, with a file .bat

or powershell script running on a Windows machine, clear the cache of Chrome or Firefox?

I promise I took a look.

+7


source to share


4 answers


In Chrome, you can clear the cache by deleting the contents of the Cache folder in %LocalAppData%\Google\Chrome\User Data\Default\Cache

. History, cookies, etc. are the SQLite database files in the parent folder, so you can also get rid of them if you want things to go, like in the Internet Explorer example:



$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\$_" 
    }
}

      

+7


source


Powershell that kills chrome and clears all chrome user profiles:



taskkill /F /IM "chrome.exe"
Start-Sleep -Seconds 5
$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            #'Login Data',
            'Top Sites',
            'Visited Links'
            #'Web Data'
            )
$Folders = Get-ChildItem "$($env:LOCALAPPDATA)\Google\Chrome\User Data" | ?{ $_.PSIsContainer -and $_.Name -eq "Default" -or $_.Name -like "Profile*"}
$Folders | ForEach-Object {
    $tmp = $_
    $Items | ForEach-Object { 
        if((Test-Path -Path "$tmp\$_" )){
            Remove-Item "$tmp\$_" 
        }
    }
}

      

+3


source


Here is my cleanup script that contains an improved version of Eric's script. It includes the Chrome, Chromium and IE directories. the variable $DaysToDelete

determines how many days the cache data should be kept on the machine.

$DaysToDelete = 1

$temporaryIEDir = "C:\users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" ## Remove all files and folders in user Temporary Internet Files. 
$cachesDir = "C:\Users\*\AppData\Local\Microsoft\Windows\Caches"  ## Remove all IE caches. 
$cookiesDir = "C:\Documents and Settings\*\Cookies\*" ## Delets all cookies. 
$locSetDir = "C:\Documents and Settings\*\Local Settings\Temp\*"  ## Delets all local settings temp 
$locSetIEDir = "C:\Documents and Settings\*\Local Settings\Temporary Internet Files\*"   ## Delets all local settings IE temp 
$locSetHisDir = "C:\Documents and Settings\*\Local Settings\History\*"  ## Delets all local settings history

Get-ChildItem $temporaryIEDir, $cachesDir, $cookiesDir, $locSetDir, $locSetIEDir, $locSetHisDir -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) } | remove-item -force -Verbose -recurse -ErrorAction SilentlyContinue

$DaysToDelete = 7

$crLauncherDir = "C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Chromium\User Data\Default"
$chromeDir = "C:\Users\*\AppData\Local\Google\Chrome\User Data\Default"
$chromeSetDir = "C:\Users\*\Local Settings\Application Data\Google\Chrome\User Data\Default"

$Items = @("*Archived History*", "*Cache*", "*Cookies*", "*History*", "*Login Data*", "*Top Sites*", "*Visited Links*", "*Web Data*")

$items | ForEach-Object {
$item = $_ 
Get-ChildItem $crLauncherDir, $chromeDir, $chromeSetDir -Recurse -Force -ErrorAction SilentlyContinue | 
    Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) -and $_ -like $item} | ForEach-Object -Process { Remove-Item $_ -force -Verbose -recurse -ErrorAction SilentlyContinue }
}

      

+2


source


Great, Anyidea, how to accomplish this on Mac.

-1


source







All Articles