Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created May 13, 2019 12:12
Show Gist options
  • Save baba-s/6f518a6ef99368bb7bf05c5f4a394683 to your computer and use it in GitHub Desktop.
Save baba-s/6f518a6ef99368bb7bf05c5f4a394683 to your computer and use it in GitHub Desktop.
using System.IO;
using UnityEditor;
public static class EmptyFolderDeleter
{
[MenuItem( "Tools/Delete Empty Folder" )]
private static void Delete()
{
DoDelete( "Assets" );
AssetDatabase.Refresh();
}
private static void DoDelete( string path )
{
foreach ( var dir in Directory.GetDirectories( path ) )
{
DoDelete( dir );
var files = Directory.GetFiles( dir );
if ( files.Length != 0 ) continue;
var dirs = Directory.GetDirectories( dir );
if ( dirs.Length != 0 ) continue;
AssetDatabase.DeleteAsset( dir );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment