怎么用Delphi7实现文件夹的压缩????

解决方案 »

  1.   

    var dbpathname:string;
        AccessEngine :DBEngine;
    begin
      AccessEngine:=CoDBEngine.Create;
      with dm_zt.Query_ZhTao do
      begin
        dbpathname:=fieldbyname('db_pathname').asstring;
      end;
      if FileExists(dbpathname) then
      begin
      try
      try
      AccessEngine:=CoDbEngine.Create;
      if  FileExists(extractfilepath(dbpathname)+'tempback.dat') then  deletefile(extractfilepath(dbpathname)+'tempback.dat')
      else
      begin
      AccessEngine.CompactDatabase(dbpathname,extractfilepath(dbpathname)+'tempback.dat','',0,';pwd=B102901010816');
      DeleteFile(dbpathname);
      renameFile(extractfilepath(dbpathname)+'tempback.dat',dbpathname);
      end;
      except
       ShowMessage('压缩失败');
      // raise;
       end;
      finally
       ShowMessage('压缩成功');   end;
      

  2.   

    www.51delphi.com去找找看有没有控件
      

  3.   

    vclZip相当好,我就用这个压缩的文件稼里的所有文件
      

  4.   

    delphi里面带的有ZLib单元,
    可以实现将文件压缩成Zib格式的文件
      

  5.   

    //添加 ZLIB 引用
    手动添加文件,设一个S  StringList : TStrings;
    begin
          StringList := TStringList.Create;
           try
              with StringList do begin
                Add(filename+'.dat');
                Add(filename+'.in1');
                Add(filename+'.in2');
                end;
               CompressFiles(StringList,filename+'.zip');
               label1.Caption:='压缩数据成功';
            finally
              StringList.free;
            end;
         end;//如果用对话框,使用多选属性,把files传给files
    //Files 要压缩的文件夹(或多个文件),Filename 目标文件,后缀你自己指定
    procedure CompressFiles(Files : TStrings; const Filename : String);
    var
      infile, outfile, tmpFile : TFileStream;
      compr : TCompressionStream;
      i,l : Integer;
      s : String;
    begin
    if Files.Count > 0 then
    begin
    outFile := TFileStream.Create(Filename,fmCreate);
    try
    { the number of files }
    l := Files.Count;
    outfile.Write(l,SizeOf(l));
    for i := 0 to Files.Count-1 do
    begin
    infile := TFileStream.Create(Files[i],fmOpenRead);
    try
    { the original filename }
    s := ExtractFilename(Files[i]);
    l := Length(s);
    outfile.Write(l,SizeOf(l));
    outfile.Write(s[1],l);
    { the original filesize }
    l := infile.Size;
    outfile.Write(l,SizeOf(l));
    { compress and store the file temporary}
    tmpFile := TFileStream.Create('tmp',fmCreate);
    compr := TCompressionStream.Create(clMax,tmpfile);
    try
    compr.CopyFrom(infile,l);
    finally
    compr.Free;
    tmpFile.Free;
    end;
    { append the compressed file to the destination file }
    tmpFile := TFileStream.Create('tmp',fmOpenRead);
    try
    outfile.CopyFrom(tmpFile,0);
    finally
    tmpFile.Free;
    end;
    finally
    infile.Free;
    end;
    end;
    finally
    outfile.Free;
    end;
    DeleteFile('tmp');
    end;
    end;//解压缩 Filename原文件  DestDirectory 目标目录
    procedure DecompressFiles(const Filename, DestDirectory : String);
    var
    dest,s : String;
    decompr : TDecompressionStream;infile, outfile : TFilestream;
    i,l,c : Integer;
    begin
    dest := IncludeTrailingPathDelimiter(DestDirectory);
    infile := TFileStream.Create(Filename,fmOpenRead);
    try
    { number of files }
    infile.Read(c,SizeOf(c));
    for i := 1 to c do
    begin
    { read filename }
    infile.Read(l,SizeOf(l));
    SetLength(s,l);
    infile.Read(s[1],l);
    { read filesize }
    infile.Read(l,SizeOf(l));
    { decompress the files and store it }
    s := dest+s; //include the path
    outfile := TFileStream.Create(s,fmCreate);
    decompr := TDecompressionStream.Create(infile);
    try
    outfile.CopyFrom(decompr,l);
    finally
    outfile.Free;
    decompr.Free;
    end;
    end;
    finally
    infile.Free;
    end;
    end;
      

  6.   

    zlib vclzip 都不错。
    vclzip最简单。
    with vclzip1 do
    begin
    zipname:='1111.zip';
    fileslist.add('c:\*.*');
    zip;
    end;