简体   繁体   English

忽略zip中的树状结构,并使用DotNetZip提取根目录

[英]Ignore arborescence in a zip and extract in root with DotNetZip

I have a password protected zipped file which contains another pw zipped file and I want to retrieve a xml file under a folder 0 inside the second zip. 我有一个受密码保护的压缩文件,其中包含另一个pw压缩文件,我想在第二个zip文件中的文件夹0下检索一个xml文件。 But I would like to have this xml in the root folder (args[0]), Do you have an idea ? 但是我想将此XML放在根文件夹(args [0])中,您有想法吗?

It is always extracting in root/0/project.xml and I want root/project.xml actually I want the xml in the same folder than the first zip. 它总是在root / 0 / project.xml中解压缩,实际上我希望root / project.xml我希望xml与第一个zip位于同一文件夹中。

using (ZipFile zip = ZipFile.Read(args[0])) {

     zip.Password = "pass1";
     zip.ExtractAll(".",ExtractExistingFileAction.OverwriteSilently);
     using (ZipFile zip2 = ZipFile.Read("0.xtz"))
     {
          ZipEntry e = zip2["0/project.xml"];
          e.ExtractWithPassword(".", ExtractExistingFileAction.OverwriteSilently, "pass2");

     }

}

将ZipFile的FlattenFoldersOnExtract属性设置为true

I found a particular answer in my case. 我找到了一个具体的答案。 If you know the name of the file, the trick is to keep only the filename 如果您知道文件名,诀窍是仅保留文件名

ZipEntry e = zip2["0/project.xml"];
e.Filename="project.xml"
e.ExtractWithPassword(".", ExtractExistingFileAction.OverwriteSilently, "pass2");

You can also make a loop if you have several entries to remove any folder containing "/" and keep the filename only. 如果您有多个条目来删除任何包含“ /”的文件夹并仅保留文件名,则也可以进行循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM