Remove Empty Directories using c#

private static void DeleteEmptyDirectory(string startLocation)
{
foreach (var directory in Directory.GetDirectories(startLocation))
{
DeleteEmptyDirectory(directory);
if (Directory.GetFiles(directory).Length == 0 &&
Directory.GetDirectories(directory).Length == 0)
{
Directory.Delete(directory, false);
}
}
}

Leave a Reply

Your email address will not be published.