ZIPTV压缩 控件包 使用方法

本文介绍了使用Delphi中的ZIPTV控件包进行文件压缩与解压缩的方法。通过两个核心函数,CompressFile与DeCompressFile,实现了文件夹的压缩与解压缩功能。并提供了详细的代码示例。
用 ZIPTV 控件包实现
用到其中的 TZip 和 TUnZip 控件
函数:
function DeCompressFile(sourceFile, targetPath: string): Boolean;
var
  FilesExtracted: Integer;
begin
  result := False;
  UnZIP1.ArchiveFile := sourceFile; // archive filename
  //   UnZIP1.Passwords.Add('123');
  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:='huaruan';
  FilesCompressed := Zip1.Compress();
  //   ShowMessage( 'Files Compressed: ' + IntToStr( FilesCompressed ) );
  result := true;
end;
调用例子:
   if not CompressFile( 'c:\temp\', 'c:\test.zip') then
     begin
       showmessage('压缩文件失败,请检查路径正确性!');
       exit;
     end;
//-------------------------------------
    if not deCompressFile('c:\test.zip', 'c:\temp\') then
    begin
      showmessage('解压压缩文件失败,请检查是否为该系统的压缩文件!');
      exit;
    end;

转载于:https://my.oschina.net/u/582827/blog/1531594

站里以前那个 6.8.4 是编译不了的。ZipTV 6.8.4 for Delphi 4, 5, 6 and 7 with source codeYOU MAY USE THIS RELEASE FOR EVALUATION PURPOSES ONLY!SOFTWARE COMPANIES NEED SUPPORT FOR QUALITY PRODUCTS.YOU ARE NOT ALLOWED TO USE THIS RELEASE TO MAKE MONEYOR USE IT FOR ANY OTHER COMMERCIAL PURPOSES.IF YOU LIKE THIS SOFTWARE: BUY IT!INSTALLATION============Extract the contents of the archive to a directory of your choice. Start Delphi. Close all open projects.Add the location of the ZipTV Source folder to the Library path: - From the menu choose: Tools -> Environment Options - In the Environment Options window click on the Library tab - Add the location to the source folder to the Library path - Click OKCompile the run-time package: - From the menu choose: File -> Open - Navigate to the ZipTV Source folder - Open the run-time package file: ztv#0rt.dpk (replace # with your Delphi version number) You will see a warning: "Cannot find resource file: ztv#0rt.res. Recreated." Click: OK - Click: Compile This will create the file ztv#0rt.bpl in your delphiin folder - Close the window - Copy the file ztv#0rt.bpl from delphiin to windowssystem (or windowssystem32 depending on your Windows version)Install the design-time package: - From the menu choose: File -> Open - Navigate to the ZipTV Source folder - Open the design-time package file: tziptv#.dpk (replace # with your Delphi version number) You will see a warning: "Cannot find resource file: tziptv#.res. Recreated." Click: OK - Click: Install The following four tabs will be added to your component palette: ZTV Compress ZTV Decompress ZTV Tools ZTV Volumes - Close the windowEnjoy :)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值