batch script to clean and archive unreal engine projects

This post has been updated to include the removal of generated BuiltData assets.

Working in Unreal Engine alone or with a team produces a lot of temporary files that the engine uses to either make the project work or make it pretty. It holds those temp files in specific folders that are safe to delete when you are ready to archive or share the project.

If you are using source control, you should or would already have these folders to be ignored thus saving your team from downloading all your temp files. But what do you do if you are using Dropbox or similar service as your source control with a small team? You are unable to ignore those folders without setting up an annoying workaround. All the temp files, huge amounts of space, will be uploaded not only taking up your (or team’s) storage space and network bandwidth but it also makes the archives heavy, annoying to handle and take a stupid amount of time to download when you want to work on them again.

Running this script saved many 10’s of GB per project and over the years of working with clients on many varieties of renderings, games, and experiences using Unreal Engine we’ve removed 100’s of GB of temp data. It adds up quick!

You might be asking why don’t I just manually select the folders each time and delete them. When a project is finished and I am ready to archive it until some future point, I run a batch script in the outermost parent folder to remove all the temp folders recursively in all the versions of the project that have been completed by me or a member of my team. Some team members may have created a project to test an asset or learn some code to help in the main project. Maybe a member of the team, who is learning Unreal Engine is working in an outside project so they are contained until their work is ready giving them the option to do whatever they want.

What I’m saying is that there may be projects inside of projects or multiple to many versions of sections of a project. Instead of going into each one and deleting those folders, I can run one script and boom. Done.

Let’s learn about Batch scripting!

Batch is a scripting language for Windows. Much of what it does can also be done manually, but its power comes from the ease of double-clicking and done.

Here is the script to RemoveAllTempFolders.bat

FOR /d /r %%d IN ("Build","Intermediate","Saved") DO @IF EXIST "%%d" rd /s /q "%%d"

To use this, open Notepad and paste this code in. Save it as “RemoveAllTempFolder.bat”

How it’s used:

The script should be placed in the outer-most folder of a project that you want to clean. For example,

//The file path to the project's main foler that contains
//all Unreal Engine project folders.

You would place “RemoveAllTempFolders.bat” inside “\SuperCoolUnrealProject\” and double-click to run it.

WARNING: running this here will remove ALL Build, Intermediate, and Saved folders inside of this directory AND subdirectories the script finds inside this path. Though, obviously that’s kind of the point.

If there was a nested project folder here:

//The file path to a nested project used for testing a piece of the environment 

the script will only delete the temp folders here down, never going up a folder.

If you don’t want it to delete your build folders, simply remove “Build” from the script and the same goes for adding onto it. If you’d also like it to delete the Binaries folder, add “Binaries” to the list of folders. Like so:

FOR /d /r %%d IN ("Binaries","Build","Intermediate","Saved") DO @IF EXIST "%%d" rd /s /q "%%d"

How it works:

First off, there is A LOT of very nifty things you can do. If you’d like to learn more about batch scripts, the Microsoft documentation provides definitions, syntax, and useful examples for what you can create.

Breaking our script down:

General intention – Loop inside this folder and all subfolders, search for all folders with the following names, if it exists, quietly delete it, continue until all are deleted.

Definitions: (From the Microsoft documentation)

FOR : Loop command: all options Files, Directory, List
/d : Directory
/r : Recurse into subfolders
%%d : The folders found to perform this action on
IN : A clause of the FOR command
(“Saved”) : The folder(s) that it is looking for
DO : The actions clause for the FOR command
@IF EXIST “%%D” : The condition to continue only if the directory exists
rd : An internal command to delete
/s : Delete all files and subfolders in addition to the folder itself
/q : Quiet – do not display Y/N confirmation
“%%D” : Directory is found, quietly delete it and all subfolders

Now you know how to write simple, powerful scripts for Windows to take care of some mundane tasks.

happy scripting!

P.S. Batch scripts are powerful and unforgiving. Use them wisely!

Site Footer