Skip to content

Instantly share code, notes, and snippets.

@hl2guide
Last active July 20, 2024 01:04
Show Gist options
  • Select an option

  • Save hl2guide/a6b0c67506d4021fe669eaa4a8022ec9 to your computer and use it in GitHub Desktop.

Select an option

Save hl2guide/a6b0c67506d4021fe669eaa4a8022ec9 to your computer and use it in GitHub Desktop.
PowerShell script that clears Visual Studio Code User Data caches. Code.exe must be closed and $userdataFolder must match your system. Can improve slow performance and free up disk space.
# Clears the Visual Studio Code User Data caches
# Backup your Visual Studio Code user folder before running!
# === Start Edit
$userdataFolder = "C:\Portable Software\PortableApps\PortableApps\Visual Studio Code\data\user-data"
# === End Edit
$cacheFolder = $userdataFolder + "\Cache"
$cachedDataFolder = $userdataFolder + "\CachedData"
$cachedExtensionVSIXsFolder = $userdataFolder + "\CachedExtensionVSIXs"
# Checks if Visual Studio Code is active
if(Get-Process "Code" -ErrorAction SilentlyContinue)
{
Write-Host "Please close Visual Studio Code first. Code.exe is running."
exit
}
if((Test-Path $cacheFolder) -eq $false -or `
(Test-Path $cachedDataFolder) -eq $false -or `
(Test-Path $cachedExtensionVSIXsFolder) -eq $false)
{
Write-Host "Please check the following paths exist."
Write-Host "$cacheFolder"
Write-Host "$cachedDataFolder"
Write-Host "$cachedExtensionVSIXsFolder"
exit
}
# Gets the files lists
$cacheFolderFiles = gci $cacheFolder -Recurse
$cachedDataFolder = gci $cachedDataFolder -Recurse
$cachedExtensionVSIXsFiles = gci $cachedExtensionVSIXsFolder -Recurse
# Combines many lists to one
$filesToRemove = $cacheFolderFiles + `
$cachedDataFolder + $cachedExtensionVSIXsFiles
# Loops through final list deleting files and subfolders
foreach($item in $filesToRemove)
{
$path = $item.FullName
Write-Host "Deleting: $path"
Remove-Item -LiteralPath $path -ErrorAction SilentlyContinue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment