Löscht rekursiv leere Unterverzeichnisse in einer Verzeichnisstruktur.
public static void DeleteEmptySubdirectories(string path)
{
try
{
foreach (var directory in Directory.EnumerateDirectories(path))
{
DeleteEmptySubdirectories(directory);
}
if (!Directory.EnumerateFileSystemEntries(path).Any())
{
Directory.Delete(path);
}
}
catch (Exception e)
{
throw new IOException($"Exception on deleting empty subdirectories in path '{path}'. See inner exception for details.", e);
}
}
2 Kommentare zum Snippet