Skip to content

Instantly share code, notes, and snippets.

@snlehton
Created December 11, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snlehton/891f13e36b042ee3b500 to your computer and use it in GitHub Desktop.
Save snlehton/891f13e36b042ee3b500 to your computer and use it in GitHub Desktop.
public static class RemoveEmptyDirectories
{
[MenuItem("Tools/EditorHacks/Remove empty directories...")]
public static void MenuItem_RemoveEmptyDirectories()
{
RemoveEmptyDirectoriesRecursive("Assets/");
}
private static void RemoveEmptyDirectoriesRecursive(string path)
{
var files = Directory.GetFiles(path);
var directories = Directory.GetDirectories(path);
if (files.Length == 0 && directories.Length == 0)
{
if (EditorUtility.DisplayDialog("Empty Directory", "Found empty directory\n" + path + "\n\nRemove?", "OK", "Cancel"))
{
Debug.LogWarning("REMOVE " + path);
AssetDatabase.DeleteAsset(path);
}
}
foreach (var directory in directories)
{
RemoveEmptyDirectoriesRecursive(directory);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment