[CSharp] Zip 파일 압축, 해제

CSharp
using (ZipArchive zipArchive = ZipFile.OpenRead(LOCAL_FILE)) { foreach (ZipArchiveEntry zipArchiveEntry in zipArchive.Entries) { try { string folderPath = Path.GetDirectoryName(Path.Combine(LOCAL_ZIPARCHIVE_PATH, zipArchiveEntry.FullName)); // if (!Directory.Exists(LOCAL_ZIPARCHIVE_PATH)) { Directory.CreateDirectory(LOCAL_ZIPARCHIVE_PATH); } // zipArchiveEntry.ExtractToFile(Path.Combine(LOCAL_ZIPARCHIVE_PATH, zipArchiveEntry.FullName), true); } catch (PathTooLongException pt_ex) { Console.WriteLine(pt_ex); } } } using (FileStream fileStream = new FileStream(SFTP_DOWNLOAD_LOCAL_PATH, FileMode.Create, FileAccess.ReadWrite)) { using (ZipArchive zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Update)) { try { foreach (string filePath in Directory.EnumerateFiles(DOWNLOAD_LOCAL_ZIPARCHIVE_PATH, "*.*", SearchOption.AllDirectories)) { string relativePath = filePath.Substring(DOWNLOAD_LOCAL_ZIPARCHIVE_PATH.Length + 1); try { zipArchive.CreateEntryFromFile(filePath, relativePath); } catch (PathTooLongException pt_ex) { Console.WriteLine(pt_ex); } } } catch (Exception ex) { Console.WriteLine(ex); } finally { zipArchive.Dispose(); fileStream.Close(); } } }
Read More