How to Use ziptv compressed control package

Source: Internet
Author: User

Implement with ziptv control package
The tzip and tunzip controls are used.
Function:
Function decompressfile (sourcefile, targetpath: string): Boolean;
VaR
Filesextracted: integer;
Begin
Result: = false;
Unzip1.archivefile: = sourcefile; // archive filename
// Unzip1.passwords. Add ('20140901 ');
Unzip1.confirmoverwrites: = false; // default = false
Unzip1.recursedirs: = true; // default = false
Unzip1.filespec. Clear ();//
Unzip1.filespec. Add ('*. *'); // *. * = extract all
Unzip1.extractdir: = targetpath ;//
Filesextracted: = unzip1.extract ();
If filesextracted = 0 then
Result: = false
Else
Result: = true;
End;

Function compressfile (sourcepath, targetfname: string): Boolean;
VaR
Filescompressed: integer;
Begin
Result: = false;
If fileexists (targetfname) then
Erasefile (targetfname, doallowundo); // erasefile is in ztvbase. Pas
Zip1.archivefile: = targetfname; // archive filename
Zip1.dateattribute: = dafiledate; // Default Value
Zip1.storeddirnames: = sdrelative; // Default Value
Zip1.compressmethod: = cmdeflate; // Default Value
Zip1.recursedirs: = true; // default = false
Zip1.switch: = swadd; // Default Value
Zip1.storeemptysubdirs: = false; // Default Value
Zip1.encryptheaders: = false; // default = false
Zip1.excludespec. Clear ();
Zip1.filespec. Clear ();
Zip1.filespec. Add (sourcepath + '*.*');
// Test with c: \ windows \ *. txt
//************************************** **************************
// Note: For a better understanding of how the Attributes property
// Works with file attributes see demo demos \ filescan \ fs_demo.dpr.
//************************************** **************************
// See the Attributes property in the object inspector
// Set zip1 Attributes property by calling the setattribute Method
Zip1.setattribute (fszeroattr, true); // default
Zip1.setattribute (fsarchive, true); // default
Zip1.setattribute (fsdirectory, true); // default = false
Zip1.setattribute (fshidden, true); // default = false
Zip1.setattribute (fsreadonly, true); // default
Zip1.setattribute (fssysfile, true); // default = false
// See the attributesex property in teh object inspector
// Set the attributesex property by calling the setattributeex method.
// Exclude none
Zip1.setattributeex (fszeroattr, false); // default
Zip1.setattributeex (fsarchive, false); // default
Zip1.setattributeex (fsdirectory, false); // default
Zip1.setattributeex (fshidden, false); // default
Zip1.setattributeex (fsreadonly, false); // default
Zip1.setattributeex (fssysfile, false); // default
// Unzip1.password: = 'huaruany ';
Filescompressed: = zip1.compress ();
// Showmessage ('files compressed: '+ inttostr (filescompressed ));
Result: = true;
End;
Call example:
If not compressfile ('C: \ temp \ ', 'c: \ test.zip') then
Begin
Showmessage ('failed to compress the file. Please check the correctness of the path! ');
Exit;
End;
//-------------------------------------
If not decompressfile ('C: \ test.zip ', 'c: \ temp \') then
Begin
Showmessage ('failed to decompress the compressed file. check whether it is a compressed file of the system! ');
Exit;
End;

----- From http://www.delphibbs.com/keylife/iblog_show.asp? Xid = 25386

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.