DotNetZip How Add Selected Files without creating

2019-06-09 04:21发布

I want to add in zip file "test" all pdf files from path

using (var zip = new ZipFile())
                {
                    zip.AddSelectedFiles("*.pdf",path);
                    zip.Save(path+"/test.zip"); 
                }

when test.zip file is created have this directory :

**test.zip**\Users\administrator\Documents\vs2010\Projects\my project\**pdf files**

How to make all pdf documents to be directly in test.zip

 test.zip\pdf files

1条回答
Rolldiameter
2楼-- · 2019-06-09 05:18

Please try the following,

 using (ZipFile zip = new ZipFile())
  {
    string[] files = Directory.GetFiles(path);
    // filter the files for *.pdf
    zip.AddFiles(files, "Test"); //Test Folder 
    zip.Save(path+"/test.zip"); 
  }
查看更多
登录 后发表回答