Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Last active April 5, 2023 20:34
Show Gist options
  • Save ArtemAvramenko/cbe636b9641f897c5e5b80ee08192051 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/cbe636b9641f897c5e5b80ee08192051 to your computer and use it in GitHub Desktop.
Extract zip file with backslashes in .NET C#
private void ExtractZip(string zipPath, string folderPath)
{
using var zip = ZipFile.Open(zipPath, ZipArchiveMode.Read);
foreach (var entry in zip.Entries)
{
var correctPath = entry.FullName.Replace("\\", "/");
var extractedFileInfo = new FileInfo(Path.Combine(folderPath, correctPath));
var entryDirectory = extractedFileInfo.Directory!.FullName;
if (!Directory.Exists(entryDirectory))
{
Directory.CreateDirectory(entryDirectory);
}
if (Path.GetFileName(extractedFileInfo.FullName).Length > 0)
{
entry.ExtractToFile(extractedFileInfo.FullName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment