Last active
April 23, 2025 13:04
-
-
Save Solessfir/0f7d5ed02be195db124bb5cc851229ed to your computer and use it in GitHub Desktop.
Cleans up an Unreal Engine project directory
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
:: Copyright (c) Solessfir under MIT license | |
:: This batch file cleans up an Unreal Engine project directory by deleting temporary files and cached shaders. | |
:: It supports UE4, UE5, and custom Unreal Engine versions. | |
:: Options: | |
:: 1. Project Cleanup - Cleans project-specific folders and, for standard engines, engine-specific AppData folders. | |
:: 2. Engine Settings Cleanup - Cleans engine settings in AppData (applies to standard engines). | |
:: 3. AppData Cleanup - Cleans all Unreal Engine-related folders in AppData. | |
:: 0. Help - Displays detailed information about each option. | |
@echo off | |
title Unreal Engine Cleanup | |
setlocal EnableDelayedExpansion | |
:: Set root directory to the script's location | |
set "RootDirectory=%~dp0" | |
set "RootDirectory=%RootDirectory:~0,-1%" | |
:: Locate the .uproject file | |
for %%i in ("%RootDirectory%\*.uproject") do ( | |
set "UprojectFilePath=%%~i" | |
goto :UprojectLocationFound | |
) | |
cd .. | |
set "RootDirectory=%cd%" | |
for %%i in ("%RootDirectory%\*.uproject") do ( | |
set "UprojectFilePath=%%~i" | |
goto :UprojectLocationFound | |
) | |
echo [91mError: No .uproject file found in %RootDirectory% or its parent directory.[0m | |
goto :ExitWithPause | |
:UprojectLocationFound | |
:: Extract Engine version from .uproject file | |
for /f "tokens=2 delims=: " %%a in ('findstr /i /c:"EngineAssociation" "%UprojectFilePath%"') do ( | |
set "EngineVersion=%%a" | |
set "EngineVersion=!EngineVersion:~1,-2!" | |
) | |
:: Check for custom engine | |
if "!EngineVersion!"=="" ( | |
echo Custom engine detected. Skipping engine-specific AppData cleanup. | |
echo. | |
set "IsCustomEngine=1" | |
) else ( | |
set "IsCustomEngine=0" | |
:: Get major and minor version (e.g., 4.27) for standard engines | |
for /f "tokens=1-2 delims=." %%a in ("!EngineVersion!") do ( | |
set "EngineVersion=%%a.%%b" | |
) | |
) | |
:: Extract project name | |
for %%a in ("%UprojectFilePath%") do ( | |
set "ProjectName=%%~na" | |
) | |
:: Define IDE config directories | |
set "RiderConfig=%RootDirectory%\.idea" | |
set "VsConfig=%RootDirectory%\.vs" | |
set "VscodeConfig=%RootDirectory%\.vscode" | |
:Prompt | |
echo [97mPlease enter an option from [92m1 [97mto [92m3[97m, or [92m0[97m for help:[0m | |
echo. [92m1[0m. Project Cleanup[0m | |
echo. [92m2[0m. Engine Settings Cleanup[0m | |
echo. [92m3[0m. AppData Cleanup[0m | |
echo: | |
set /p UserInput="> " | |
if "%UserInput%"=="0" goto :Help | |
if "%UserInput%"=="1" goto :ProjectCleanup | |
if "%UserInput%"=="2" goto :EngineSettingsCleanup | |
if "%UserInput%"=="3" goto :AppDataCleanup | |
echo Invalid input. Do you want to try again? (Y/N) | |
set /p UserInput="> " | |
if /i "%UserInput%"=="Y" goto :Prompt | |
goto :DirectExit | |
:Help | |
cls | |
echo [92m1. Project Cleanup[0m | |
echo. What it does: Cleans up your project folder to free up space and remove unnecessary files. | |
echo. What gets removed: | |
echo. - Temporary folders like "Intermediate" and "Script" in your project directory. | |
echo. - For Unreal Engine 4 or 5 (not custom engines), temporary files in AppData (e.g., user settings for that engine version). | |
echo. - Specific files in "Binaries\Win64" like old shipping builds or debug files (e.g., %ProjectName%-Win64-Shipping.exe). | |
echo. - Most files in the "Saved" folder, except your collections and source control settings. | |
echo. - The entire "Binaries" folder. | |
echo. - Files from tools like Rider, Visual Studio, or VS Code, but keeps some settings (e.g., vcs.xml). | |
echo. - Temporary plugin files (e.g., plugin "Binaries" and "Intermediate" folders). | |
echo. Good for: When your project feels slow or takes up too much space. | |
echo. | |
echo [92m2. Engine Settings Cleanup[0m | |
echo. What it does: Removes Unreal Engine settings stored on your computer, but only for standard engines (UE4/UE5). | |
echo. What gets removed: | |
echo. - The "UnrealHeaderTool" folder in AppData. | |
echo. - Subfolders like "Collections," "Config," "Logs," etc., in AppData\UnrealEngine for all engine versions. | |
echo. Good for: Resetting engine preferences or clearing logs without touching your project. | |
echo. | |
echo [92m3. AppData Cleanup[0m | |
echo. What it does: Deletes all Unreal Engine-related data stored in AppData, including shaders and settings. | |
echo. What gets removed: | |
echo. - Everything in AppData\UnrealEngine (all engine versions). | |
echo. - Everything in AppData\Unreal Engine (global settings). | |
echo. - The "UnrealHeaderTool" folder. | |
echo. Good for: A full reset of Unreal Engine data on your computer (e.g., if shaders are broken or you're troubleshooting). | |
echo. | |
echo Press any key to return to the main menu. | |
pause >nul | |
cls | |
goto :Prompt | |
:ProjectCleanup | |
cls | |
:: Delete project-specific folders | |
set "project_folders=Intermediate Script" | |
for %%f in (%project_folders%) do ( | |
if exist "%RootDirectory%\%%f" ( | |
echo Deleting folder %RootDirectory%\%%f | |
rd /s /q "%RootDirectory%\%%f" | |
) | |
) | |
:: Delete engine-specific AppData folders | |
set "appdata_folders=Config Intermediate" | |
for %%f in (%appdata_folders%) do ( | |
if exist "%localappdata%\UnrealEngine\%EngineVersion%\%%f" ( | |
echo Deleting folder %localappdata%\UnrealEngine\%EngineVersion%\%%f | |
rd /s /q "%localappdata%\UnrealEngine\%EngineVersion%\%%f" | |
) | |
) | |
if exist "%localappdata%\UnrealBuildTool" ( | |
echo Deleting folder %localappdata%\UnrealBuildTool | |
rd /s /q "%localappdata%\UnrealBuildTool" | |
) | |
:: Delete specific files in Binaries\Win64 | |
set "BinariesDir=%RootDirectory%\Binaries\Win64" | |
set "files_to_delete=OpenImageDenoise.dll tbb.dll tbb12.dll %ProjectName%-Win64-Shipping.exe %ProjectName%-Win64-Shipping.exp %ProjectName%-Win64-Shipping.lib %ProjectName%-Win64-Shipping.pdb %ProjectName%-Win64-Shipping.target" | |
for %%f in (%files_to_delete%) do ( | |
if exist "%BinariesDir%\%%f" ( | |
echo Deleting file %BinariesDir%\%%f | |
del /f /q "%BinariesDir%\%%f" | |
) | |
) | |
:: Clean Saved folder, preserving Collections and SourceControlSettings.ini | |
for /r "%RootDirectory%\Saved" %%i in (*) do ( | |
set "filepath=%%i" | |
if "!filepath:Collections=!"=="!filepath!" ( | |
if not "%%~nxi"=="SourceControlSettings.ini" ( | |
echo Deleting file: %%i | |
attrib -r "%%i" 2>nul | |
del "%%i" 2>nul | |
if exist "%%i" echo Failed to delete: %%i | |
) else ( | |
echo Preserving: %%i | |
) | |
) else ( | |
echo Preserving file in Collections: %%i | |
) | |
) | |
:: Remove empty folders in Saved | |
for /f "delims=" %%a in ('dir /s /b /ad "%RootDirectory%\Saved" ^| sort /r') do ( | |
rd "%%a" 2>nul | |
) | |
:: Delete Binaries folder | |
if exist "%RootDirectory%\Binaries" ( | |
echo Deleting folder %RootDirectory%\Binaries | |
rd /s /q "%RootDirectory%\Binaries" | |
) | |
:: Clean IDE-specific files if config folders exist | |
if exist "%RiderConfig%" ( | |
for /r "%RiderConfig%" %%f in (*) do ( | |
set "file=%%~nxf" | |
if /i not "!file!"=="vcs.xml" if /i not "!file!"=="workspace.xml" ( | |
echo Deleting file %%f | |
del "%%f" >nul 2>&1 | |
) | |
) | |
) | |
if exist "%VsConfig%" ( | |
echo Deleting folder %VsConfig% | |
rd /s /q "%VsConfig%" | |
) | |
if exist "%VscodeConfig%" ( | |
echo Deleting folder %VscodeConfig% | |
rd /s /q "%VscodeConfig%" | |
) | |
:: Delete additional IDE files | |
set "ide_files=%RootDirectory%\%ProjectName%.uproject.DotSettings.user %RootDirectory%\%ProjectName%.sln %RootDirectory%\.vsconfig %RootDirectory%\%ProjectName%.code-workspace" | |
for %%f in (%ide_files%) do ( | |
if exist "%%f" ( | |
echo Deleting file %%f | |
del /f /q "%%f" | |
) | |
) | |
:: Clean Plugins subfolders | |
for /d /r "%RootDirectory%\Plugins" %%d in (*) do ( | |
if "%%~nd"=="Binaries" ( | |
echo Deleting plugin folder %%d | |
rd /s /q "%%d" | |
) else if "%%~nd"=="Intermediate" ( | |
echo Deleting plugin folder %%d | |
rd /s /q "%%d" | |
) | |
) | |
echo [92m%ProjectName% cleanup successfully completed.[0m | |
echo: | |
goto :ExitWithPause | |
:EngineSettingsCleanup | |
cls | |
if exist "%localappdata%\UnrealHeaderTool" ( | |
echo Deleting folder %localappdata%\UnrealHeaderTool | |
rd /s /q "%localappdata%\UnrealHeaderTool" | |
) | |
set "subfolders=Collections Config Logs Content Intermediate Saved" | |
for /d %%d in ("%localappdata%\UnrealEngine\*") do ( | |
for %%s in (%subfolders%) do ( | |
if exist "%%d\%%s" ( | |
echo Deleting folder %%d\%%s | |
rd /s /q "%%d\%%s" | |
) | |
) | |
) | |
echo: | |
echo [92mEngine Settings cleanup successfully completed.[0m | |
echo: | |
goto :ExitWithPause | |
:AppDataCleanup | |
cls | |
if exist "%localappdata%\UnrealEngine" ( | |
echo Deleting folder %localappdata%\UnrealEngine | |
rd /s /q "%localappdata%\UnrealEngine" | |
) | |
if exist "%appdata%\Unreal Engine" ( | |
echo Deleting folder %appdata%\Unreal Engine | |
rd /s /q "%appdata%\Unreal Engine" | |
) | |
if exist "%localappdata%\UnrealHeaderTool" ( | |
echo Deleting folder %localappdata%\UnrealHeaderTool | |
rd /s /q "%localappdata%\UnrealHeaderTool" | |
) | |
echo: | |
echo [92mAppData cleanup successfully completed.[0m | |
echo: | |
goto :ExitWithPause | |
:ExitWithPause | |
pause | |
exit /b 0 | |
:DirectExit | |
exit /b 0 | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment