C Drive Full? Automate the Cleanup with This Simple Batch File!
This article reflects my current understanding as part of my professional learning journey. While I strive for accuracy, the content may be updated as my expertise deepens.
📝 Published: 27 Apr 2025 | 🔄 Updated: 13 May 2025 | ✍️ By Santosh Kumar Tripathi
My C: drive was almost full. Instead of cleaning manually every time, I created a batch file to automate common cleanup tasks.
What It Does
- Deletes Windows Temp files
- Cleans up %temp% user temp files
- Clears the Prefetch folder
- Empties Recycle Bin
Notes
- Run as Administrator
- This deletes temporary files only – safe, but still use with care
- You can schedule this using Task Scheduler for auto cleanup
Result
I freed up 15+ GB instantly — no tools, no third-party apps.
git clone href="https://github.com/santoshtripathi30/c-drive-automate-cleanup-batch-file
Feel free to tweak and use!
@echo off
setlocal
REM Set the username (this will automatically use the logged-in user)
set "USERNAME=%USERNAME%"
echo Deleting Chrome and Visual Studio cache and other data for user: %USERNAME%
REM Define Chrome user data path
set "CHROME_USER_DATA=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data"
REM Loop through all profiles for Chrome
for /d %%p in ("%CHROME_USER_DATA%\Profile*") do (
echo Deleting Service Worker, Code Cache, and Cache for: %%p
REM Delete Service Worker
del /f /s /q "%%p\Service Worker\*"
REM Delete Code Cache
del /f /s /q "%%p\Code Cache\*"
REM Delete Cache
del /f /s /q "%%p\Cache\*"
)
REM Loop through all Visual Studio versions for JSProjSystem
for /d %%v in ("C:\Users\%USERNAME%\AppData\Local\Microsoft\VisualStudio\*") do (
if exist "%%v\JSProjectSystem" (
echo Deleting JSProjectSystem for: %%v
del /f /s /q "%%v\JSProjectSystem\*"
)
)
REM Loop through all Visual Studio versions for WebTools
for /d %%v in ("C:\Users\%USERNAME%\AppData\Local\Microsoft\VisualStudio\*") do (
if exist "%%v\WebTools" (
echo Deleting WebTools for: %%v
del /f /s /q "%%v\WebTools\*"
)
)
REM Additional cleanup (Windows, npm, etc.)
del /f /s /q "C:\Windows\SoftwareDistribution\Download\*"
del /f /s /q "C:\Windows\Minidump\*"
del /f /q "C:\Windows\MEMORY.DMP"
del /f /s /q "C:\Users\%USERNAME%\AppData\Local\AzureFunctionsTools\*"
del /f /s /q "C:\Users\%USERNAME%\AppData\Local\npm-cache\*"
del /f /s /q "C:\Users\%USERNAME%\AppData\Local\Microsoft\Edge\User Data\*"
echo.
echo Cleanup complete.
pause