Last active
May 13, 2024 18:56
-
-
Save Solessfir/0f7d5ed02be195db124bb5cc851229ed to your computer and use it in GitHub Desktop.
Fast way to clean Unreal Engine left offs
This file contains 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
@echo off | |
:: This batch file cleans up an Unreal Engine project directory by deleting certain folders and files. | |
:: It offers three options to the user | |
:: 1. Will clean Project only | |
:: 2. Will clean ...AppData\Local\UnrealEngine saved folders | |
:: 3. Will clean all Unreal Engine related folder in the AppData. This will also remove compiled Shaders for all the projects | |
setlocal EnableDelayedExpansion | |
title UE Project Cleanup | |
set RootDirectory=%~dp0 | |
set RootDirectory=%RootDirectory:~0,-1% | |
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%[0m | |
goto ExitWithPause | |
:UprojectLocationFound | |
for /f "tokens=2 delims=: " %%a in ('findstr /i /c:"EngineAssociation" "%UprojectFilePath%"') do ( | |
set EngineVesion=%%a | |
set EngineVesion=!EngineVesion:~1,-2! | |
) | |
for /f "tokens=1-3 delims=." %%a in ("%EngineVersion%") do ( | |
set EngineVersion=%%a.%%b | |
) | |
if not defined EngineVesion ( | |
echo [91mError: No EngineAssociation found in %UprojectFilePath%[0m | |
goto ExitWithPause | |
) | |
for %%a in (%UprojectFilePath%) do ( | |
set ProjectName=%%~na | |
) | |
set RiderConfig=%RootDirectory%\.idea | |
set VsConfig=%RootDirectory%\.vs | |
set VscodeConfig=%RootDirectory%\.vscode | |
:Prompt | |
echo [97mPlease enter an option from [92m1 [97mto [92m3[97m:[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%==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 | |
:ProjectCleanup | |
cls | |
if exist "%RootDirectory%\Intermediate" ( | |
echo Deleting folder %RootDirectory%\Intermediate | |
rd /s /q "%RootDirectory%\Intermediate" | |
) | |
if exist "%RootDirectory%\Script" ( | |
echo Deleting folder %RootDirectory%\Script | |
rd /s /q "%RootDirectory%\Script" | |
) | |
if exist "%localappdata%\UnrealEngine\%EngineVesion%\Config" ( | |
echo Deleting folder %localappdata%\UnrealEngine\%EngineVesion%\Config | |
rd /s /q "%localappdata%\UnrealEngine\%EngineVesion%\Config" | |
) | |
if exist "%localappdata%\UnrealEngine\%EngineVesion%\Intermediate" ( | |
echo Deleting folder %localappdata%\UnrealEngine\%EngineVesion%\Intermediate | |
rd /s /q "%localappdata%\UnrealEngine\%EngineVesion%\Intermediate" | |
) | |
if exist "%localappdata%\UnrealBuildTool" ( | |
echo Deleting folder %localappdata%\UnrealBuildTool | |
rd /s /q "%localappdata%\UnrealBuildTool" | |
) | |
set BinariesDir=%RootDirectory%\Binaries\Win64 | |
if exist "%BinariesDir%\OpenImageDenoise.dll" ( | |
echo Deleting file %BinariesDir%\OpenImageDenoise.dll | |
del /f /q "%BinariesDir%\OpenImageDenoise.dll" | |
) | |
if exist "%BinariesDir%\tbb.dll" ( | |
echo Deleting file %BinariesDir%\tbb.dll | |
del /f /q "%BinariesDir%\tbb.dll" | |
) | |
if exist "%BinariesDir%\tbb12.dll" ( | |
echo Deleting file %BinariesDir%\tbb12.dll | |
del /f /q "%BinariesDir%\tbb12.dll" | |
) | |
if exist "%BinariesDir%\%ProjectName%-Win64-Shipping.exe" ( | |
echo Deleting file %BinariesDir%\%ProjectName%-Win64-Shipping.exe | |
del /f /q "%BinariesDir%\%ProjectName%-Win64-Shipping.exe" | |
) | |
if exist "%BinariesDir%\%ProjectName%-Win64-Shipping.exp" ( | |
echo Deleting file %BinariesDir%\%ProjectName%-Win64-Shipping.exp | |
del /f /q "%BinariesDir%\%ProjectName%-Win64-Shipping.exp" | |
) | |
if exist "%BinariesDir%\%ProjectName%-Win64-Shipping.lib" ( | |
echo Deleting file %BinariesDir%\%ProjectName%-Win64-Shipping.lib | |
del /f /q "%BinariesDir%\%ProjectName%-Win64-Shipping.lib" | |
) | |
if exist "%BinariesDir%\%ProjectName%-Win64-Shipping.pdb" ( | |
echo Deleting file %BinariesDir%\%ProjectName%-Win64-Shipping.pdb | |
del /f /q "%BinariesDir%\%ProjectName%-Win64-Shipping.pdb" | |
) | |
if exist "%BinariesDir%\%ProjectName%-Win64-Shipping.target" ( | |
echo Deleting file %BinariesDir%\%ProjectName%-Win64-Shipping.target | |
del /f /q "%BinariesDir%\%ProjectName%-Win64-Shipping.target" | |
) | |
:: Clean Saved folder except Collections and SourceControlSettings.ini | |
for /r "%RootDirectory%\Saved" %%i in (*) do ( | |
if not "%%~nxi"=="SourceControlSettings.ini" ( | |
for %%j in ("%%~dpi.") do ( | |
if /i not "%%~nxj"=="Collections" ( | |
del "%%i" | |
) | |
) | |
) | |
) | |
:: Remove empty folders | |
for /f "delims=" %%a in ('dir /s /b /ad "%RootDirectory%\Saved" ^| sort /r') do ( | |
rd "%%a" 2>nul | |
) | |
if exist "%RiderConfig%" ( | |
goto CleanupBinaries | |
) | |
if exist "%VsConfig%" ( | |
goto CleanupBinaries | |
) | |
if exist "%VscodeConfig%" ( | |
goto CleanupBinaries | |
) | |
echo: | |
echo [92mProject cleanup successfully completed[0m | |
echo: | |
goto ExitWithPause | |
:CleanupBinaries | |
if exist "%RootDirectory%\Binaries" ( | |
echo Deleting folder %RootDirectory%\Binaries | |
rd /s /q "%RootDirectory%\Binaries" | |
) | |
if exist "%RootDirectory%\%ProjectName%.sln.DotSettings.user" ( | |
echo Deleting file %RootDirectory%\%ProjectName%.sln.DotSettings.user | |
del /f /q "%RootDirectory%\%ProjectName%.sln.DotSettings.user" | |
) | |
if exist "%RootDirectory%\%ProjectName%.sln" ( | |
echo Deleting file %RootDirectory%\%ProjectName%.sln | |
del /f /q "%RootDirectory%\%ProjectName%.sln" | |
) | |
if exist "%RootDirectory%\.vsconfig" ( | |
echo Deleting file %RootDirectory%\.vsconfig | |
del /f /q "%RootDirectory%\.vsconfig" | |
) | |
if exist "%RootDirectory%\%ProjectName%.code-workspace" ( | |
echo Deleting file %RootDirectory%\%ProjectName%.code-workspace | |
del /f /q "%RootDirectory%\%ProjectName%.code-workspace" | |
) | |
if exist "%RiderConfig%" ( | |
for /r "%RiderConfig%" %%f in (*) do ( | |
set "file=%%~nxf" | |
set "extension=%%~xf" | |
set "path=%%~dpf" | |
if /i "!extension!" neq ".xml" ( | |
echo Deleting file %%f | |
del "%%f" >nul 2>&1 | |
) else ( | |
if /i "!file!" neq "vcs.xml" if /i "!file!" neq "workspace.xml" ( | |
echo Deleting file %%f | |
del "%%f" >nul 2>&1 | |
) | |
) | |
) | |
) | |
if exist "%VsConfig%" ( | |
rd /s /q "%VsConfig%" | |
) | |
if exist "%VscodeConfig%" ( | |
rd /s /q "%VscodeConfig%" | |
) | |
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: | |
echo [92mProject cleanup successfully completed[0m | |
echo: | |
goto ExitWithPause | |
:EngineSettingsCleanup | |
cls | |
:: Remove crash reports | |
if exist "%localappdata%\UnrealHeaderTool" ( | |
rd /s /q "%localappdata%\UnrealHeaderTool" | |
) | |
for /d %%d in ("%localappdata%\UnrealEngine\*") do ( | |
if exist "%%d\Collections" ( | |
rd /s /q "%%d\Collections" | |
) | |
if exist "%%d\Config" ( | |
rd /s /q "%%d\Config" | |
) | |
if exist "%%d\Logs" ( | |
rd /s /q "%%d\Logs" | |
) | |
if exist "%%d\Content" ( | |
rd /s /q "%%d\Content" | |
) | |
if exist "%%d\Intermediate" ( | |
rd /s /q "%%d\Intermediate" | |
) | |
if exist "%%d\Saved" ( | |
rd /s /q "%%d\Saved" | |
) | |
) | |
echo: | |
echo [92mEngine Settings cleanup successfully completed[0m | |
echo: | |
goto ExitWithPause | |
:AppDataCleanup | |
cls | |
rd /s /q "%localappdata%\UnrealEngine" | |
rd /s /q "%appdata%\Unreal Engine" | |
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