The system. Zip unit is added to Delphi xe2 and the entire folder can be compressed in one sentence.

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.