Removing Empty Folders in Unity

This post shares a small (bumeta for empty folderst useful) recipe for getting rid of empty folders in Unity. This annoying thing usually happens when you switch between different git branches, since different branches may add/remove folders.

Git doesn’t like to deal with empty folders, it doesn’t let you delete those empty folders… In case you’ll delete the .meta files, Unity will re-create those later (since the folders still exist).

Show me the code

The code is available in this link: Remove empty folders

Add the class into an editor folder in your project. It will add a new menu item (under Tools/Remove empty folders) that will allow you to remove empty folders.

NOTE: the code contains a dryRun flag that will only iterate and list all the empty folders it’s going to remove. Change this to false to actually make the code delete anything 🙂

This entry was posted in Unity and tagged , , , , . Bookmark the permalink.

2 Responses to Removing Empty Folders in Unity

  1. Free Debreuil says:

    We had the same sort of issue in our project, we have it run automatically when unity starts, as not everyone using unity is a programmer and would know when to run the script.

  2. Alex Sink says:

    Big fan of this. If you’ve ever moved/deleted folders in git when using unity “visible meta files” you’ll run into this issue all the time.

    Currently using something very similar ( ).

    Whitelisting is done globally and then it rescans after the whitelist times out.

    The most up to date version uses InitializeOnLoad attribute to make sure it starts running when the project starts, not just when asset importer is invoked. Between InitializeOnLoad and making it a part of the asset import pipeline nobody should have to run it manually.

Leave a Reply

Your email address will not be published. Required fields are marked *