简体   繁体   中英

Zipping contents of a list file using DotNetZip library

I have a .lst file that has the paths of various data that has to be zipped. The path may be a direct path to an executable or a path to a log file or may contain a wildcard like - c:\\abc*.exe. How do I zip all of them into a single zip file? Thanks

DotNetZip Library is @:http://dotnetzip.codeplex.com/wikipage?title=CS-examples&referringTitle=Examples

Contents of .lst file :

c:\\log\\abc.log

c:\\log\\def.log

c:\\ping*.bat

c:\\ping*.exe

This is what I tried:

using (ZipFile zip = new ZipFile())     
{                      
   StreamReader file = File.OpenText("C:\\pingman\\pingzipA.lst");
   string read = String.Empty;

   while ((read = file.ReadLine()) != null)                  
   {                                      
      zip.AddSelectedFiles(read, true);    
      zip.Save("c:\\update.zip");       
   }

   file.Close();   
}

Here is a link that has a TON of Examples take a look as use the examples to work for what you are trying to do.. there is even an example that uses Wild-Cards

DontNetZip Library Site with Examples

Try something like:

 while ((read = file.ReadLine()) != null)                  
 {              
   if (read.Contains("*"))                        
   {
       zip.AddSelectedFiles(read, true);    
   }
   else
   {
       zip.AddFile(read);
   }
 }
 zip.Save("c:\\update.zip");       

Got it to work.

if (read.Contains("*"))
                    {
                        int i = read.IndexOf("*");
                        string path = read.Substring(0, i--);
                        string doc = read.Substring(i+1);
                        zip.AddSelectedFiles(doc, @path, true);
                    }
                    else
                    {
                        zip.AddFile(read);
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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