Skip to content

Commit

Permalink
feat: remove empty directories
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 19, 2024
1 parent 63235dd commit 8608eb5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions Util/DirectoryHelper.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}

0 comments on commit 8608eb5

Please sign in to comment.