Recent

Author Topic: Compress all files in the local directory without the problem of the local direc  (Read 387 times)

jianwt

  • Jr. Member
  • **
  • Posts: 97
I have a folder "temp" with 4 files in it. temp\1 , temp\2\324 ,temp\3,temp\4\N;

I want to compress all files (including folders) in the temp folder, but the forum code I refer to will compress the temp folder together. I only want to compress the 1;2\324;3;4\N files into a compressed package separately, not together with the temp folder. That is to say, you can only see 4 files when you open the compressed package, instead of seeing the temp folder, and you can see 4 files when you enter.

Network translation, I don't know if I understand, thank you first.

Code: Pascal  [Select][+][-]
  1. var
  2.   DataBack_upFileName: string;
  3.   AZipper: TZipper;
  4.   szPathEntry: string;
  5.   i: integer;
  6.   ZEntries: TZipFileEntries;
  7.   TheFileList: TStringList;
  8.   RelativeDirectory: string;
  9. begin  
  10. SaveDialog1.Filter := ' zip压缩文件(*.zip)|*.zip';
  11.   SaveDialog1.Title := '选择zip压缩路径和文件名';
  12.  
  13.   if SaveDialog1.Execute then
  14.    begin
  15.     if SaveDialog1.FileName='' then
  16.      begin
  17.      exit;
  18.      end
  19.     else
  20.      begin
  21.        try
  22.        AZipper := TZipper.Create;
  23.       try
  24.         try
  25.          RelativeDirectory:=ExtractFilePath(ParamStr(0)) + 'temp\';
  26.         AZipper.Clear;
  27.         ZEntries := TZipFileEntries.Create(TZipFileEntry);
  28.          If DirPathExists(RelativeDirectory) then
  29.         begin
  30.  
  31.           i:=RPos(PathDelim,ChompPathDelim(RelativeDirectory));
  32.           szPathEntry:=LeftStr(RelativeDirectory,i);
  33.            TheFileList:=TstringList.Create;
  34.            try
  35.              FindAllFiles(TheFileList, RelativeDirectory);
  36.              for i:=0 to TheFileList.Count -1 do
  37.               begin
  38.                ZEntries.AddFileEntry(TheFileList[i],CreateRelativePath(TheFileList[i],szPathEntry));
  39.               end;
  40.            finally
  41.             if Assigned(TheFileList) then
  42.              FreeAndNil(TheFileList);
  43.           //TheFileList.Free;
  44.         end;
  45.        end;
  46.        if (ZEntries.Count > 0) then
  47.          AZipper.ZipFiles(ZEntries);
  48.       except
  49.         On E: EZipError do
  50.           E.CreateFmt('无法创建zip文件%原因: %s', [LineEnding, E.Message])
  51.       end;
  52.    finally
  53.     if Assigned(ZEntries) then
  54.     FreeAndNil(ZEntries);
  55.      if Assigned(AZipper) then
  56.      FreeAndNil(AZipper);
  57.   end;
  58.        Application.MessageBox('数据压缩成功!!',
  59.       '提示!',  mb_OK);
  60.  
  61.     except
  62.       Application.MessageBox('数据压缩失败!!',
  63.       '错误提示!', MB_ICONERROR + mb_OK);
  64.     end;
  65.     end;
  66.    end;
  67.  end;
  68.                                                      
  69.  
« Last Edit: May 14, 2024, 07:59:52 am by jianwt »


 

TinyPortal © 2005-2018