Created
June 27, 2017 17:04
-
-
Save unity3dcollege/1c6ca527d8ae57de735e9c7747084940 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.IO; | |
using System.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
public class CleanEmptyFoldersEditorExtension : EditorWindow | |
{ | |
private static string deletedFolders; | |
[MenuItem("Tools/Clean Empty Folders")] | |
private static void Cleanup() | |
{ | |
deletedFolders = string.Empty; | |
var directoryInfo = new DirectoryInfo(Application.dataPath); | |
foreach(var subDirectory in directoryInfo.GetDirectories("*.*", SearchOption.AllDirectories)) | |
{ | |
if (subDirectory.Exists) | |
{ | |
ScanDirectory(subDirectory); | |
} | |
} | |
Debug.Log("Deleted Folders:\n" + (deletedFolders.Length > 0 ? deletedFolders : "NONE")); | |
} | |
private static string ScanDirectory(DirectoryInfo subDirectory) | |
{ | |
Debug.Log("Scanning Directory: " + subDirectory.FullName); | |
var filesInSubDirectory = subDirectory.GetFiles("*.*", SearchOption.AllDirectories); | |
if (filesInSubDirectory.Length == 0 || | |
!filesInSubDirectory.Any(t => t.FullName.EndsWith(".meta") == false)) | |
{ | |
deletedFolders += subDirectory.FullName + "\n"; | |
subDirectory.Delete(true); | |
} | |
return deletedFolders; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pythonInRelay No problem! Happy to help.