我现在要做服务端控制客户端来接收文件,但是客户端那边是目录,我想把客户端的目录压缩成一个文件,然后通过socket进行传送这个文件到服务端指定目录,但是现在不知道如何压缩目录成一个文件,请各位大侠多多指教,给100分!

解决方案 »

  1.   

    对方有RAR的话,直接调用
    winrar命令行参考
      rar a -o+ c:\11.mdb c:\temp\myback.rar不然用第三方压缩控件VCLZip
      

  2.   

    补充一下一楼:  {--------------压缩----------------------}
      htys:='d:\tmp_data.rar';
      dbpath := 'd:\tmp';
      aa:='winrar.exe a -mm -r '+ htys + ' ' + dbpath + '\htys';
      if winexec(pchar(aa),1)<=31 then
      begin
        messagebox(handle,'压缩操作失败!','提示信息',0);
        exit;
      end;  {-------------解压缩----------------------}
      file_name:='d:\htys\tmp_data.rar';
      dbpath := 'd:\tmp';
      aa:='winrar e -o+ '+file_name+' '+dbpath;
      if not fileexists(file_name) then
      begin
        messagebox(handle,pchar(file_name+'文件不存在,无法进行解压缩操作!'),'提示信息',0);
        exit;
      end;  if winexec(pchar(aa),sw_hide)<=31 then
      begin
        messagebox(handle,'解压缩操作失败!','提示信息',0);
        exit;
      end;
    //VCLZip控件VCLZip1.FilesList.Add('...'); //  
    VCLZip1.ZipName := ...
      Try
        VCLZip1.Zip;      //压缩文件
      Except
        Application.MessageBox('压缩失败', '错误', MB_OK);  
      End;
      

  3.   

    用winrar可以
    file_path:=winrar_path+' a -ibck -r -sfx '+dir_path1+' '+dir_path2+'\*.*';
    WinExec(pchar(file_path),SW_HIde);
    winrar_path为winrar.exe路径
    如d:\winrar\winrar.exe
    rir_path1为缩文件路径名称
    d:\wendang\aa
    rir_path1为要压缩文件夹路径名称
    如:d:\wendang\aa
    a -ibck -r -sfx 为winrar命令参数,可以看winrrar帮助
      

  4.   

    用VCLZIP这个控件能否压缩目录啊,好像只能够压缩目录中的文件,子目录救不能压缩拉
      

  5.   

    可以拉,只要再设置两个属性
    要想能够压缩目录,那么就必须让VCLZip的控件Recurse和RelativePaths这两个属性置为True同时代码中如下添加:
      VCLZip2.FilesList.Add('E:\Download\*.*');
      //VCLZip1.RelativePathList.Add('E:\Download');
      VCLZip2.ZipName := 'E:\aaaa.rar';
      Try
        VCLZip2.Zip;      //压缩文件
      Except
        Application.MessageBox('压缩失败', '错误', MB_OK);
      End;非常感谢以上大侠的回答!再次谢过!