zoukankan      html  css  js  c++  java
  • ZIPTV压缩 控件包 使用方法

    用 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;

    -----转自http://www.delphibbs.com/keylife/iblog_show.asp?xid=25386

  • 相关阅读:
    CSS3中的Transition属性详解
    jq 全选/取消效果
    多维数组问题 int (*a)[] int []
    C语言输入多组问题~ungetc回退字符到stdin
    2015-12-14重启博客之旅
    转载~kxcfzyk:Linux C语言多线程库Pthread中条件变量的的正确用法逐步详解
    lsof 一切皆文件
    转载自~浮云比翼: 不忘初衷,照顾好自己。
    转载自~浮云比翼:Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)
    梳理回顾
  • 原文地址:https://www.cnblogs.com/linyawen/p/2022449.html
Copyright © 2011-2022 走看看