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 打开网页的两种方法

Delphi 按f11程序全屏

Delphi 获取所有磁盘分区另类方法

Delphi滚动标题栏文字

Delphi2010 关于record类型rtti反射的用途和方法

Delphi memo1 光标跟随鼠标移动

Delphi 屏幕渐变效果的源代码

Delphi 把窗体客户区图像保存到文件或剪切板

Delphi strtodatetime 这个函数在win7下出错

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



打赏

取消

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

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

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

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

评论

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