簡體   English   中英

從ZipFile內部檢索文件名

[英]Retrieve file names from inside ZipFile

就像標題所說的那樣,我需要從zip文件中讀取文件名。 我將名稱輸入2D字符串數組(以及其他數據)。 這是我想做的開始的例子。

private String[,] ArrayFiller(ZipFile MyZip)
{
    int count = 0;
    ZipFile zipfile = ZipFile.Read();
    int zipSize = MyZip.Count;
    string[,] MyArr = new string[zipSize, zipSize];

    foreach (ZipEntry e in zipfile.EntriesSorted)
    {
        //otherArr[count,count] = e; -adds the file, but I need title
    }
    return MyArr;
}

我確定我缺少一些簡單的東西,但是似乎在ZipFile類中找不到“文件名”屬性。 導入的包稱為Ionic.Zip。

也許這是某種壓縮對象的屬性?

您需要使用ZipArchive類。 MSDN

    using (ZipArchive archive = ZipFile.OpenRead(zipPath))
    {
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            Console.WriteLine(entry.FullName);
            //entry.ExtractToFile(Path.Combine(destFolder, entry.FullName));
        }
    } 

ZipArchive類可能會給您帶來更多的運氣。

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
          // The file name is entry.FullName
     }
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM