Skip to content

Bullrich/UnityFolderCleaner

Repository files navigation

Unity Folder Cleaner

CodeFactor

Small utility to delete empty folder from the Unity project.

Based from a script in Unity3D College

Usage

Open the utility at Window > Tools > Clean Empty Folders.

It will scan all the folders in your project and delete empty folders.

Installation

Using Open UPM

You can install this package using OpenUPM's command line tool:

openupm add dev.bullrich.folder-cleaner

Adding the package to the Unity project manifest

  • Navigate to the Packages directory of your project.

  • Adjust the project manifest file manifest.json in a text editor.

    • Ensure https://package.openupm.com is part of scopedRegistries.
      • Ensure dev.bullrich is part of scopes.
    • Add dev.bullrich.folder-cleaner to dependencies, stating the latest version.

    A minimal example ends up looking like this. Please note that the version X.Y.Z stated here is to be replaced with the latest released version which is currently openupm.

    {
      "scopedRegistries": [
        {
          "name": "package.openupm.com",
          "url": "https://package.openupm.com",
          "scopes": [
            "dev.bullrich"
          ]
        }
      ],
      "dependencies": {
        "dev.bullrich.folder-cleaner": "X.Y.Z"
      }
    }
  • Switch back to the Unity software and wait for it to finish importing the added package.

Enabling verbose logs

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.

Add editor test

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 Packages directory of your project.

  • Adjust the project manifest file manifest.json in a text editor.

    • Ensure dev.bullrich.folder-cleaner is part of testables.

    A minimal example ends up looking like this.

    {
      "scopedRegistries": [
        ...
      ],
      "testables": [
        "dev.bullrich.folder-cleaner"
      ],
      "dependencies": {
        ...
      }
    }
  • 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 testables attribute.

    • Within the Unity software's Project window expand the Packages node.
    • Right-click on the Folder Cleaner child node and choose Reimport.
    • Wait for the Unity software to finish re-importing the package.
  • In the Unity software select Main Menu -> Window -> Test Runner.

  • Within the Test Runner window click on the EditMode tab and the click Run All button.

  • If all the tests pass then the installation was successful.

About

Remove empty folder from the Editor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages