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

  • 相关阅读:
    关于Thread ThreadPool Parallel 的一些小测试demo
    VS附加到进程调试
    netcore 实现一个简单的Grpc 服务端和客户端
    CodeSmith 找不到请求的 .Net Framework Data Provider
    ocelot集成consul服务发现
    使用ocelot作为api网关
    关于add migration 报错的问题解决方案
    关于多线程efcore dbcontext 的解决方案。
    docker mysql 容器报too many connections 引发的liunx磁盘扩容操作
    关于liunx 机器脱机环境(netcore)Nuget包迁移的问题
  • 原文地址:https://www.cnblogs.com/linyawen/p/2022449.html
Copyright © 2011-2022 走看看