Skip to content

Instantly share code, notes, and snippets.

@guibranco
Created May 9, 2025 14:21
Show Gist options
  • Save guibranco/2a62b97838426313fbe51ad1d515cfe2 to your computer and use it in GitHub Desktop.
Save guibranco/2a62b97838426313fbe51ad1d515cfe2 to your computer and use it in GitHub Desktop.
Development Environment Cleanup Script
@echo off
setlocal enabledelayedexpansion
:: Define the list of directories to clean
set DIR_LIST=bin obj node_modules target\debug target\tmp .angular .terraform visuals\traces visuals\videos visuals\screenshots visuals\information
set ADDITIONAL_DIR_LIST=%temp% C:\Windows\Temp C:\Users\%username%\AppData\Local\Temp C:\ProgramData\Microsoft\Windows\WER\ReportQueue C:\Windows\SoftwareDistribution\Download
set VS_CODE_DIR=%APPDATA%\Code\Cache %APPDATA%\Code\Cookies %APPDATA%\Code\LocalStorage %APPDATA%\Code\User\workspaceStorage
set VS_DIR=C:\Users\%username%\AppData\Local\Microsoft\VisualStudio
set PYTHON_CACHE_DIR=%APPDATA%\Local\pip\cache
set GO_CACHE_DIR=%GOPATH%\pkg\mod
set RUST_CACHE_DIR=%USERPROFILE%\.cargo
set NPM_CACHE_DIR=%APPDATA%\npm-cache
:: Log file
set LOG_FILE=cleanup_log.txt
:: Create or clear the log file
echo Cleanup started at %date% %time% > %LOG_FILE%
:: Function to clean directories
:CleanDirs
for %%d in (%DIR_LIST% %ADDITIONAL_DIR_LIST% %VS_CODE_DIR% %VS_DIR% %PYTHON_CACHE_DIR% %GO_CACHE_DIR% %RUST_CACHE_DIR% %NPM_CACHE_DIR%) do (
echo Checking directory: %%d
if exist "%%d" (
echo Deleting directory: %%d >> %LOG_FILE%
rd /s /q "%%d"
if !errorlevel! equ 0 (
echo Successfully deleted: %%d >> %LOG_FILE%
) else (
echo Error deleting: %%d >> %LOG_FILE%
)
) else (
echo Directory does not exist: %%d >> %LOG_FILE%
)
)
:: Clear NuGet cache
echo Clearing NuGet cache... >> %LOG_FILE%
nuget locals all -clear
if !errorlevel! equ 0 (
echo NuGet cache cleared successfully. >> %LOG_FILE%
) else (
echo Error clearing NuGet cache. >> %LOG_FILE%
)
:: Clean Docker resources
echo Cleaning Docker cache... >> %LOG_FILE%
docker system prune -af
if !errorlevel! equ 0 (
echo Docker cache cleaned successfully. >> %LOG_FILE%
) else (
echo Error cleaning Docker cache. >> %LOG_FILE%
)
:: Clean npm/yarn cache
echo Cleaning npm/yarn cache... >> %LOG_FILE%
npm cache clean --force
if !errorlevel! equ 0 (
echo npm/yarn cache cleaned successfully. >> %LOG_FILE%
) else (
echo Error cleaning npm/yarn cache. >> %LOG_FILE%
)
:: Clean Python cache (if using pip)
echo Cleaning Python pip cache... >> %LOG_FILE%
rd /s /q "%PYTHON_CACHE_DIR%"
if !errorlevel! equ 0 (
echo Python pip cache cleaned successfully. >> %LOG_FILE%
) else (
echo Error cleaning Python pip cache. >> %LOG_FILE%
)
:: Clean Go cache
echo Cleaning Go module cache... >> %LOG_FILE%
rd /s /q "%GO_CACHE_DIR%"
if !errorlevel! equ 0 (
echo Go module cache cleaned successfully. >> %LOG_FILE%
) else (
echo Error cleaning Go module cache. >> %LOG_FILE%
)
:: Clean Rust Cargo cache
echo Cleaning Rust Cargo cache... >> %LOG_FILE%
rd /s /q "%RUST_CACHE_DIR%"
if !errorlevel! equ 0 (
echo Rust Cargo cache cleaned successfully. >> %LOG_FILE%
) else (
echo Error cleaning Rust Cargo cache. >> %LOG_FILE%
)
:: End of script
echo Cleanup completed at %date% %time% >> %LOG_FILE%
endlocal
@guibranco
Copy link
Author

Development Environment Cleanup Script

This batch script is designed to clean up various cache, temporary, and unnecessary files from different tools and environments in a development machine. It helps free up disk space by targeting directories and caches from common technologies such as:

  • VSCode: Clears workspace storage, cache, and local storage.
  • Visual Studio: Removes temporary files and cache.
  • npm/yarn: Cleans npm and yarn caches.
  • Python: Removes pip cache and virtual environments.
  • Go: Clears Go module cache.
  • Rust: Cleans Cargo cache.
  • Docker: Removes unused Docker resources (images, containers, volumes).
  • General Cleanup: Cleans system temporary files, logs, and Windows update files.

The script logs all actions to a log file (cleanup_log.txt), allowing easy tracking of what was cleaned and any errors encountered.

Run this script periodically to help maintain a clean and efficient development environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment