Home c# sharpziplib. Creating file archive in cycle

sharpziplib. Creating file archive in cycle

Author

Date

Category

Good afternoon!
I use the SharPzipLib library to create an archive.
It does not work in the cycle to transfer the file list and create an archive.
At the moment it simply deletes files.
Here is my code:

using system;
Using System.Data;
using microsoft.sqlserver.dts.runtime;
using System.Windows.Forms;
using System.io.Compression;
using icsharpcode.sharpziplib.zip;
using icsharpcode.sharpziplib.core;
   Public Void Main ()
      {
        Var MyDate = datetime.Now;
        var startofmonth = new datetime (mydate.year, mydate.month, 1);
        String rootfolderpath = @ "E: \ Download";
        String Filestodelete = @ "* T_D_FD_Dryua *";
        String [] FileList = System.io.Directory.getFiles (rootfolderpath, filestodelete);
        if (datetime.Now! = startofmonth)
        {
          Fileach (String File in FileList)
          {
            //System.diagnostics.debug.writeline(File + "Will Be Deleted");
            //System.io.file.delete(file);
            DTS.TaskResult = (int) scriptresults.success;
          }
         }
      }

How to make the archive of the necessary files correctly using this library?
Thank!


Answer 1, Authority 100%

Create an archive file:

zipfile zipfile = new zipfile (@ "C: \ temp \ existing.zip");

Add Your Files:

Public Void Add () {
  ...
  Fileach (String File in FileList)
  {
    UpdateExistingzip (File);
  }
}
Public Void UpdateExistingZip (String File) {
  // Must Call Beginupdate to Start, and CommitUpdate AT The End.
  zipfile.beginupdate ();
  //zipfile.password = "WHATEVER"; // Only If A Password is Wanted on the New Entry
  // The "add ()" Method Will Add or Overwrite AS NECESSARY.
  // WHEN THE OPTIONAL ENTINAME PARAMETER IS OMITTED, THE ENTRY WILL BE NAMED
  // With the Full Folder Path and Without The Drive E.g. "Temp / folder / test1.txt".
  //
  //zipfile.add (@"c:\temp\Folder\Test1.txt ");
  zipfile.add (File);
  // Specify the EntryName Parameter to Modify The Name As It Appears in the Zip.
  //
  //zipfile.add (@"C:\Temp\Folder\Test2.txt "," test2.txt ");
  // Continue Calling .add Until Finished.
  // Both CommitUpdate and Close Must Be Called.
  zipfile.commitUpdate ();
  zipfile.close ();
}

Made based on this https://github.com/icsharpcode/sharpziplib/wiki/updating . Code performance has not been checked.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions