Last active
April 5, 2023 20:34
-
-
Save ArtemAvramenko/cbe636b9641f897c5e5b80ee08192051 to your computer and use it in GitHub Desktop.
Extract zip file with backslashes in .NET C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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