diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs index 382c3ddf..4cba5463 100644 --- a/src/SharpCompress/Archives/IArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveExtensions.cs @@ -54,14 +54,26 @@ public static void ExtractToDirectory( var entry = entries.Entry; if (entry.IsDirectory) { + var dirPath = Path.Combine(destination, entry.Key.NotNull("Entry Key is null")); + if ( + Path.GetDirectoryName(dirPath + "/") is { } emptyDirectory + && seenDirectories.Add(dirPath) + ) + { + Directory.CreateDirectory(emptyDirectory); + } continue; } - // Create each directory + // Create each directory if not already created var path = Path.Combine(destination, entry.Key.NotNull("Entry Key is null")); - if (Path.GetDirectoryName(path) is { } directory && seenDirectories.Add(path)) + if (Path.GetDirectoryName(path) is { } directory) { - Directory.CreateDirectory(directory); + if (!Directory.Exists(directory) && !seenDirectories.Contains(directory)) + { + Directory.CreateDirectory(directory); + seenDirectories.Add(directory); + } } // Write file