【问题标题】:DotNetZip - rename file entry in zip file while compressingDotNetZip - 压缩时重命名 zip 文件中的文件条目
【发布时间】:2011-06-20 14:58:25
【问题描述】:

使用 DotNetZip,是否可以压缩文件,使 zip 列出的文件名与磁盘上的文件名不同?例如,我想将 myFile.txt 添加到一个 zip 文件中,但我希望它被称为 otherFile.txt。

【问题讨论】:

    标签: c# .net-4.0 dotnetzip


    【解决方案1】:

    来自 DotNetZip 常见问题解答:

    Add an entry, overriding its name in the archive

      using (ZipFile zip1 = new ZipFile())
      {
          zip1.AddFile("myFile.txt").FileName = "otherFile.txt"; 
          zip1.Save(archiveName);
      }
    

    【讨论】:

    • 呵呵,我们都是时不时做的。
    【解决方案2】:
            var zip = new ZipFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.zip"));
            var e = zip.AddFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "testfile.pdf"), "/");
            e.FileName = "PewPewGotcha.pdf";
            zip.Save();
    

    ZipFile 保存后,名称即会更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      相关资源
      最近更新 更多