ZIPTV壓縮 控制項包 使用方法

來源:互聯網
上載者:User

用 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.