diff --git a/DownloadTask.cs b/DownloadTask.cs index 92cf844..a327d3a 100644 --- a/DownloadTask.cs +++ b/DownloadTask.cs @@ -778,6 +778,9 @@ private void RemoveOldFiles(IDownloadTask_GetVersion info) { done += 1; this.SetStateData(done, total); } + + // remove any empty directories + DirectoryHelper.RemoveEmptyDirectories(filesPath); } private async Task DownloadFile(Uri baseUri, string filesPath, string[] outputPaths, string hash) { diff --git a/Util/DirectoryHelper.cs b/Util/DirectoryHelper.cs new file mode 100644 index 0000000..70d80d8 --- /dev/null +++ b/Util/DirectoryHelper.cs @@ -0,0 +1,12 @@ +namespace Heliosphere.Util; + +internal static class DirectoryHelper { + internal static void RemoveEmptyDirectories(string root) { + foreach (var path in Directory.GetDirectories(root)) { + RemoveEmptyDirectories(path); + if (!Directory.EnumerateFileSystemEntries(path).Any()) { + Directory.Delete(path, false); + } + } + } +}