Last active
July 20, 2024 01:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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