-
[C#] Zip 파일 목록, XMLC#/기초 2023. 10. 20. 13:32
UnZip 하지않고 Zip 파일 열어서 파일 목록 가져오고
xml 파일 다루기
List<Dictionary<string, string>> OpenFileApp(string path) { var appPath = path; //string appPath = Directory.GetCurrentDirectory() + @"\AppPackages\Robot.app"; var appList = GetListAppFilesName(appPath); var dicAspec = new Dictionary<string, byte[]>(); var aspecList = new List<Dictionary<string, string>>(); foreach (var app in appList) { var archiveAppFile = ZipFile.OpenRead(app); Dictionary<string, byte[]> getFiles = GetFiles(archiveAppFile); //dicAspec.Append(GetFiles(archiveAppFile)); AppVerDic.Add(app, getFiles); // TODO: 버전 2개이상일 경우 최신버전 가져오기 var latestVerAspec = getFiles.OrderByDescending(x => x.Key).First(); dicAspec.Add(latestVerAspec.Key, latestVerAspec.Value); } foreach (var aspec in dicAspec) { XmlDocument xmlDoc = new XmlDocument(); string xml = Encoding.UTF8.GetString(aspec.Value); xmlDoc.LoadXml(xml); XmlNode xmlNodeMetadata = xmlDoc.SelectSingleNode("package/metadata"); XmlNodeList xmlNodeList = xmlNodeMetadata.ChildNodes; var dicXml = new Dictionary<string, string>(); foreach (XmlNode xmlNode in xmlNodeList) { dicXml.Add(xmlNode.Name, xmlNode.InnerText); } aspecList.Add(dicXml); } return aspecList; } List<string> GetListAppFilesName(string path) { var appPath = path; //string unzipPath = UserPath; var appList = new List<string>(); DirectoryInfo di = new DirectoryInfo(appPath); foreach (FileInfo File in di.GetFiles()) { if (File.Extension.ToLower().CompareTo(".app") == 0) { //string FileNameOnly = File.Name.Substring(0, File.Name.Length - 4); //string FullFileName = File.FullName; //UnzipFile(FullFileName, unzipPath + FileNameOnly); appList.Add(File.FullName); } } return appList; } public static Dictionary<string, byte[]> GetFiles(ZipArchive archive) { //using (MemoryStream ms = new MemoryStream(zippedFile)) //using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read)) var aspec = ".aspec"; var dicAspec = new Dictionary<string, byte[]>(); #region Test1 //ZipArchiveEntry entry = archive.Entries.FirstOrDefault(x => x.FullName.Contains(aspec)); //if (entry is not null) //{ // dicAspec.Add(entry.FullName, ReadStream(entry.Open())); // //dicAspec = new Dictionary<string, byte[]> // // { // // { entry.FullName, ReadStream(entry.Open())} // // }; // return dicAspec; //} #endregion Test1 #region Test2 foreach (ZipArchiveEntry entry in archive.Entries) { //var entryTest = entry.FullName.Split('/'); if (entry.FullName.Contains(aspec)) { var dirTest = Path.GetDirectoryName(entry.FullName); dicAspec.Add(entry.FullName, ReadStream(entry.Open())); //dicAspec = new Dictionary<string, byte[]> //{ // { entry.FullName, ReadStream(entry.Open())} //}; //return dicAspec; } } #endregion Test2 return dicAspec; //return archive.Entries.ToDictionary(x => x.FullName, x => ReadStream(x.Open())); } private static byte[] ReadStream(Stream stream) { using (var ms = new MemoryStream()) { stream.CopyTo(ms); return ms.ToArray(); } }
https://dlsenfl.tistory.com/entry/C-Zip-UnZip
[C#] Zip, UnZip
https://chashtag.tistory.com/24 [C#] 압축, 압축 풀기 (zip, unzip) 오늘은 폴더를 zip 파일로, zip 파일을 폴더로 만드는 방법에 대해 알아보겠습니다. 아래 코드를 구현하기 위해선 System.IO.Compression.FileSystem을
dlsenfl.tistory.com
https://dlsenfl.tistory.com/entry/C-XML-%ED%8C%8C%EC%9D%BC
[C#] XML 파일
XML 대소문자 구분함. 특수문자 사용시 적용법 1. 특수문자를 대신하는 문자를 대신 사용 다양한 특수문자가 많지만, 자주 사용하는 5개의 특수문자만 예로 들어 설명해보겠습니다. 결과값 요소
dlsenfl.tistory.com
read xml file from entry as stream
https://stackoverflow.com/questions/37957163/read-a-zip-entry-and-save-it-in-a-string
Read a zip entry and save it in a string
Ack. I am trying to open a specific entry in a zip file archive and store the contents in a string, instead of saving it to a file. I cannot use disk space for this per the client. Here's what I...
stackoverflow.com
728x90'C# > 기초' 카테고리의 다른 글
[C#] Dictionary sort (0) 2023.11.01 [C#] params 키워드 (1) 2023.10.31 [C#] Func<> (0) 2023.10.19 [C#] Directory.Delete (0) 2023.10.18 [C#] Zip, UnZip (0) 2023.10.17 댓글