The tzipfile class is mainly used in a unit. The most convenient method is its class method:
Tzipfile. extractzipfile () // decompress the ZIP file to the specified folder tzipfile. isvalid () // determine whether the specified file is a valid ZIP file tzipfile. zipdirectorycontents () // compress all files in the specified path
Test:
Uses system. zip; {compress all files under c: \ temp \ testdir to c: \ temp \ test.zip} procedure tform1.button1click (Sender: tobject); begin tzipfile. zipdirectorycontents ('C: \ temp \ test.zip ', 'c: \ temp \ testdir \'); // parameter 3 can specify CompressionAlgorithmEnd; {unzip c: \ temp \ test.zip to c: \ temp \ testdir2 \} procedure tform1.button2click (Sender: tobject); begin tzipfile. extractzipfile ('C: \ temp \ test.zip ', 'c: \ temp \ testdir2 \'); end;
The following describes how to instantiate a class:
Uses system. zip; {compression} procedure tform1.button1click (Sender: tobject); var ZIP: tzipfile; begin ZIP: = tzipfile. create; zip. open ('C: \ temp \ 001.zip ', tzipmode. zmwrite); // prepare to compress to 001.zip. add ('C: \ temp \ test.txt ', 'test.txt'); // parameter 1 is the file to be compressed; parameter 2 is the file name to be used; parameter 3: Specify the compression algorithm // zip. add... // zip. close; // The actual compression process is executed only when the file is close. However, the zip file is called before the file is destroyed. free; end; {decompress} procedure tform1.button2click (Sender: tobject); var ZIP: tzipfile; begin ZIP: = tzipfile. create; zip. open ('C: \ temp \ 001.zip ', tzipmode. zmread); zip. extractall ('C: \ temp \ 002 \ '); zip. free; end;