Small utility to delete empty folder from the Unity project.
Based from a script in Unity3D College
Open the utility at Window > Tools > Clean Empty Folders.
It will scan all the folders in your project and delete empty folders.
You can install this package using OpenUPM's command line tool:
openupm add dev.bullrich.folder-cleaner
-
Navigate to the
Packagesdirectory of your project. -
Adjust the project manifest file
manifest.jsonin a text editor.- Ensure
https://package.openupm.comis part ofscopedRegistries.- Ensure
dev.bullrichis part ofscopes.
- Ensure
- Add
dev.bullrich.folder-cleanertodependencies, stating the latest version.
A minimal example ends up looking like this. Please note that the version
X.Y.Zstated here is to be replaced with the latest released version which is currently.
{ "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "dev.bullrich" ] } ], "dependencies": { "dev.bullrich.folder-cleaner": "X.Y.Z" } } - Ensure
-
Switch back to the Unity software and wait for it to finish importing the added package.
If you want the log to list every directory that will be scanned you can add the Scripting Define Symbol
FOLDER_CLEANER_VERBOSE to your project and it be more verbose when running.
There is a unit test to ensure that there are no empty directories in the project.
If you want to add this test to your project you can add it following this steps:
-
Navigate to the
Packagesdirectory of your project. -
Adjust the project manifest file
manifest.jsonin a text editor.- Ensure
dev.bullrich.folder-cleaneris part oftestables.
A minimal example ends up looking like this.
{ "scopedRegistries": [ ... ], "testables": [ "dev.bullrich.folder-cleaner" ], "dependencies": { ... } } - Ensure
-
As noted in the official Unity documentation:
NOTE: You may need to re-import the package, because the test framework doesn't always immediately pick up changes to the
testablesattribute.- Within the Unity software's
Projectwindow expand thePackagesnode. - Right-click on the
Folder Cleanerchild node and chooseReimport. - Wait for the Unity software to finish re-importing the package.
- Within the Unity software's
-
In the Unity software select
Main Menu -> Window -> Test Runner. -
Within the Test Runner window click on the
EditModetab and the clickRun Allbutton. -
If all the tests pass then the installation was successful.