开发者

DotNetZip - rename file entry in zip file while compressing

开发者 https://www.devze.com 2023-03-14 08:12 出处:网络
Using DotNetZip, is it possible to com开发者_如何学JAVApress a file such that the zip lists a different file name for a file than the file name on disk?For example, I want to add myFile.txt to a zip f

Using DotNetZip, is it possible to com开发者_如何学JAVApress a file such that the zip lists a different file name for a file than the file name on disk? For example, I want to add myFile.txt to a zip file, but I want it to be called otherFile.txt.


From the DotNetZip FAQ:

Add an entry, overriding its name in the archive

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


        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();

Once the ZipFile is saved, the name is updated.

0

精彩评论

暂无评论...
验证码 换一张
取 消