Create(Path: String; Mode: ZipMode; [CompressionLevel: ZipCompressionLevel = -1]);
Create(Path: String; Mode: Prognoz.Platform.Interop.ForeIO.ZipMode; CompressionLevel: Prognoz.Platform.Interop.ForeIO.ZipCompressionLevel);
Path. Path and name of ZIP archive on the hard drive.
Mode. Object creation mode to work with ZIP archive.
CompressionLevel. Archive compression degree.
The Create constructor initializes a new object to work with ZIP archive.
Depending on the selected Mode mode, the Path parameter contains the path to the existing archive or name of the archive that will be created after. If a new archive is created, the folder specified in the Path parameter must already be on the hard drive.
Executing the example requires the D:\Work folder on the hard drive, this folder contains the Archives subdirectory to store archive files and the Other subdirectory to store subfiles. The D:\Work folder must also have the WDI.xls file with data. Add a link to the IO system assembly.
Sub UserProc;
Var
ZIP: IZipArchive;
Begin
ZIP := New ZipArchive.Create("D:\Work\Archives\Data.zip", ZipMode.Create);
//Compression degree
ZIP.CompressionLevel := ZipCompressionLevel.BestCompression;
//Add files to archive
ZIP.AddFile("D:\Work\WDI.xls", "WDI.xls");
ZIP.AddDirectory("D:\Work\Other");
//Free variable with saving of archive
Dispose ZIP;
End Sub UserProc;
Imports Prognoz.Platform.Interop.ForeIO;
Public Shared Sub Main(Params: StartParams);
Var
ZIP: IZipArchive = New ZipArchiveClass();
Begin
//Create an archive with specified compression degree
ZIP.Create("D:\Work\Archives\Data.zip", ZipMode.zmCreate, ZipCompressionLevel.zcBestCompression);
//Add files to archive
ZIP.AddFile("D:\Work\WDI.xls", "WDI.xls");
ZIP.AddDirectory("D:\Work\Other", "");
//Free variable with saving of archive
System.Runtime.InteropServices.Marshal.ReleaseComObject(ZIP);
End Sub;
After executing the example the Data.zip archive is created, the specified file and the Other subdirectory with all contents are added to this archive. The maximum compression degree is set for the archive.
See also: