Skip to content

Instantly share code, notes, and snippets.

@Solessfir
Last active May 13, 2024 18:56
Show Gist options
  • Save Solessfir/0f7d5ed02be195db124bb5cc851229ed to your computer and use it in GitHub Desktop.
Save Solessfir/0f7d5ed02be195db124bb5cc851229ed to your computer and use it in GitHub Desktop.
Fast way to clean Unreal Engine left offs
@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 Error: No .uproject file found in %RootDirectory%
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 Error: No EngineAssociation found in %UprojectFilePath%
goto ExitWithPause
)
for %%a in (%UprojectFilePath%) do (
set ProjectName=%%~na
)
set RiderConfig=%RootDirectory%\.idea
set VsConfig=%RootDirectory%\.vs
set VscodeConfig=%RootDirectory%\.vscode
:Prompt
echo Please enter an option from 1 to 3:
echo. 1. Project Cleanup
echo. 2. Engine Settings Cleanup
echo. 3. AppData Cleanup
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 Project cleanup successfully completed
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 Project cleanup successfully completed
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 Engine 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 AppData 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