Created
December 11, 2015 21:20
-
-
Save snlehton/891f13e36b042ee3b500 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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