【问题标题】:Adding files into a folder inside a zip file in c#在c#中将文件添加到zip文件内的文件夹中
【发布时间】:2015-03-04 12:58:26
【问题描述】:

我的压缩文件代码如下

ZipArchive zip = ZipFile.Open(destToZip, ZipArchiveMode.Create);
zip.CreateEntry("pubEd/");

string[] fileEntries = Directory.GetFiles(dirToZip);
foreach (string fileName in fileEntries)
    zip.CreateEntryFromFile(fileName,Path.GetFileName(fileName), CompressionLevel.Optimal);

zip.Dispose();

在创建 zip 文件后,在代码的第二行中,我在 zip 文件中创建了一个名为 pubEd 的文件夹。

在下一行中,我将文件添加到 zip 文件夹中。

正在发生的事情是文件被直接添加到 zip 中。

我想将这些文件添加到我在 zip 中创建的目录中。

我该怎么做?

【问题讨论】:

标签: c# zip compression archive ziparchive


【解决方案1】:

从外观上看,您会将Path.GetFileName(fileName) 更改为"pubEd/" + Path.GetFileName(fileName)。并摆脱第二行。那只是基于我对文档的阅读。我还没有真正尝试过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 2012-03-04
    • 2010-10-02
    • 1970-01-01
    相关资源
    最近更新 更多