Delphi 下 VCLZip控件的简单使用


本文整理自网络,侵删。

 

uses VCLUnZip, VCLZip;

function ComPressFile(dstFile,srcFile:string):Boolean;
var
  vclzip:TVCLZip;
begin
  Result:=False;
  vclzip:=TVCLZip.create(nil);
  try
    with vclzip do
    begin
      try
        ZipName:=dstFile;
        RecreateDirs:=true; //注意这里
        StorePaths:=False;
        FilesList.Add(srcFile);
        Recurse := True;
        Zip;
        Result:=True;
      except
        Application.MessageBox('压缩文件失败','错误',MB_OK+MB_ICONINFORMATION);
        Result:=False;
        exit;
      end;
    end;
  finally
    vclzip.Free;
  end;
end;
function UnComPressFile(sFile,sOutFile:string):Boolean;
var
  vcluzip:TVCLUnZip;
begin
  Result:=False;
  vcluzip:=TVCLUnZip.Create(nil);
  try
    with vcluzip do
    begin
      try
        ZipName:=sFile;
        ReadZip;
        FilesList.Add('*.*');
        DoAll := False;
        DestDir := sOutFile;
        RecreateDirs := False;
        RetainAttributes := True;
        Unzip;
        Result:=True;
      except
        Application.MessageBox('解压文件失败','错误',MB_OK+MB_ICONINFORMATION);
        Result:=False;
        exit;
      end;
    end;
  finally
    vcluzip.Free;
  end;
end;

 

procedure TForm1.Button1Click(Sender: TObject);
var
    ls_dir, ls_SysTempDir: string;
begin
    //if not OpenDialog1.Execute then exit;
    if not SelectDirectory('请指定文件夹', '', ls_dir) then exit;
    //    VCLZip1.ZipName :=

    ls_SysTempDir := GetEnvironmentVariable('Temp') + '/';
    VCLZip1.ZipName := ls_SysTempDir + 'ABC.db';
    VCLZip1.FilesList.Add(ls_dir + '/*.jpeg');
    VCLZip1.FilesList.Add(ls_dir + '/*.jpg');
    VCLZip1.FilesList.Add(ls_dir + '/*.bmp');       
    //VCLZip1.FilesList.Add(ls_dir + '/冒险岛/*.*');
    //VCLZip1.FilesList.Add(ls_dir + '/三国/*.*');

    VCLZip1.Recurse := False; //不包含下级目录中的文件
    VCLZip1.StorePaths := False; //不记录路径
    VCLZip1.PackLevel := 9;
    VCLZip1.Password := 'cvbom';
    try
        VCLZip1.Zip;
    except
        ShowMessage('Error!');
        exit
    end;
    MessageBox(0, '压缩成功', '成功', MB_OK + MB_ICONINFORMATION);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
    ls_dir, ls_SysTempDir: string;
    NumUnzipped: Integer;
begin
    //ls_SysTempDir := GetEnvironmentVariable('Temp') + '/';
    VCLUnZip1.ZipName := 'C:/Documents and Settings/yuantao/Local Settings/Temp/ABC.zip';
    //VCLUnZip1.ReadZip;
    VCLUnZip1.FilesList.Add('*.*');
    //VCLUnZip1.FilesList.Add(VCLUnZip1.Filename[VCLUnZip1.Count - 1]);
    VCLUnZip1.DoAll := True;
    VCLUnZip1.Password := 'cvbom';
    VCLUnZip1.DestDir := 'D:/Setup';
    VCLUnZip1.RecreateDirs := True; // don't recreate directory structures
    //VCLUnZip1.RetainAttributes := True;

    ShowMessage(IntToStr(VCLUnZip1.UnZip));

    MessageBox(0, '解压缩成功', '成功', MB_OK + MB_ICONINFORMATION);
end;

相关阅读 >>

Delphi 如何把类中的方法做参数

Delphi 一个call应该如何写?

Delphi 通过程序窗体句柄获取程序路径

Delphi比较两个位图是否相同

Delphi 的编码与解码(或叫加密与解密)函数

Delphi mediaplayer1 设置音量

Delphi strutils.dupestring - 反复字符串

Delphi webservices base64编码

Delphi版文件夹加密软件源代码

crc16.pas

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...