You're absolutely right — and you're in control now. Let's reset the noise and give you one clean, perfectly formatted, ready-to-run script.
✅ migrate-caches.bat — Final Clean Version
📌 Run as Administrator
🔁 Safely moves AI & dev caches offC:
✅ Preserves data, verifies copy, optional symlinks
💾 Reclaim 10–50+ GB of space
@echo off
:: =====================================================
:: 🔧 MIGRATE DEV CACHES TO EXTERNAL DRIVE
:: Safely moves Hugging Face, pip, npm to E:\dev-cache
:: Preserves data, verifies copy, optional symlinks
:: Run as Administrator
:: =====================================================
setlocal enabledelayedexpansion
:: === CONFIG: Change E: to your large drive ===
set EXTERNAL_DRIVE=E:
set BASE_DIR=%EXTERNAL_DRIVE%\dev-cache
:: Cache locations
set HF_SOURCE=%USERPROFILE%\.cache\huggingface
set HF_TARGET=%BASE_DIR%\huggingface
set PIP_SOURCE=%LOCALAPPDATA%\pip\cache
set PIP_TARGET=%BASE_DIR%\pip
set NPM_SOURCE=%APPDATA%\npm-cache
set NPM_TARGET=%BASE_DIR%\npm
set TORCH_TARGET=%BASE_DIR%\torch
:: Create base directory
if not exist "%BASE_DIR%" mkdir "%BASE_DIR%"
echo.
echo 🎯 Target: %BASE_DIR%
echo Existing files will be preserved.
echo Press any key to continue... & pause >nul
echo.
:: =============================
:: 🔁 MIGRATE: Hugging Face
:: =============================
call :migrate_dir "%HF_SOURCE%" "%HF_TARGET%" "Hugging Face"
:: =============================
:: 🔁 MIGRATE: pip
:: =============================
call :migrate_dir "%PIP_SOURCE%" "%PIP_TARGET%" "pip"
:: =============================
:: 🔁 MIGRATE: npm
:: =============================
call :migrate_dir "%NPM_SOURCE%" "%NPM_TARGET%" "npm"
:: =============================
:: 🔁 MIGRATE: Torch (no source, just redirect)
:: =============================
if not exist "%TORCH_TARGET%" mkdir "%TORCH_TARGET%"
echo ✅ Torch cache will use: %TORCH_TARGET%
:: =============================
:: 🔗 OPTIONAL: Create Symlinks
:: =============================
echo.
echo 🔗 Create symbolic links to redirect C:\ caches to %EXTERNAL_DRIVE%?
echo This reclaims space and keeps tools working.
echo WARNING: Requires Admin rights.
echo.
choice /c YN /m "Create symlinks? (Y/N)"
if %errorlevel% == 2 goto no_symlinks
:: Remove old dirs and link new ones
if exist "%HF_SOURCE%" rd /s /q "%HF_SOURCE%"
if not exist "%HF_SOURCE%" mklink /J "%HF_SOURCE%" "%HF_TARGET%" && echo 🔄 Linked: Hugging Face
if exist "%PIP_SOURCE%" rd /s /q "%PIP_SOURCE%"
if not exist "%PIP_SOURCE%" mklink /J "%PIP_SOURCE%" "%PIP_TARGET%" && echo 🔄 Linked: pip
if exist "%NPM_SOURCE%" rd /s /q "%NPM_SOURCE%"
if not exist "%NPM_SOURCE%" mklink /J "%NPM_SOURCE%" "%NPM_TARGET%" && echo 🔄 Linked: npm
echo.
echo 🎉 Done! Tools now use %EXTERNAL_DRIVE%. C:\ caches are links.
goto end
:no_symlinks
echo.
echo 💡 No symlinks created. Add these to your .cmd scripts:
echo.
echo set HF_HOME=%HF_TARGET%
echo set PIP_CACHE_DIR=%PIP_TARGET%
echo set TORCH_HOME=%TORCH_TARGET%
echo set TMP=%BASE_DIR%\tmp
echo set TEMP=%BASE_DIR%\tmp
echo.
echo Then run your worker as usual.
:end
echo.
echo ✅ Migration complete. You’ve just reclaimed C:!
echo Check %BASE_DIR% — your AI caches are now safe and sound.
pause
exit /b
:: ============
:: FUNCTION: Migrate and verify a directory
:: ============
:migrate_dir
set SOURCE=%~1
set TARGET=%~2
set NAME=%~3
echo 🚚 Migrating %NAME% cache...
echo From: %SOURCE%
echo To: %TARGET%
:: Source doesn't exist? Create target and skip
if not exist "%SOURCE%" (
if not exist "%TARGET%" mkdir "%TARGET%"
echo ⚠️ No %NAME% cache found at source. Target created.
echo.
exit /b
)
:: Target already exists? Skip copy
if exist "%TARGET%" (
echo 💡 Found existing cache at %TARGET%. Skipping copy.
echo