Search code examples
delphicompressionabbrevia

how to add empty folder to abbrevia tar file


i want to create a *.tar.gz file with abbrevia, i'm using below code but empty folders are not added to archive. baseDir contains empty and not empty folders.

i have found bugs that fixed about empty folders

https://sourceforge.net/p/tpabbrevia/bugs/108/

https://sourceforge.net/p/tpabbrevia/bugs/8/

How can i add these empty folders to archive?

  Zip := TAbZipper.Create(nil);
  try
    Zip.BaseDirectory := baseDir;
    Zip.StoreOptions := [soRecurse];
    Zip.Filename := targetFile;
    Zip.FArchive.StoreOptions := [soRecurse];
    Zip.AddFiles('*', faDirectory + faAnyFile);
    Zip.CloseArchive;
  finally
    Zip.Free;
  end;

Solution

  • i did not manage to create an archive that contains empty folder by using TPabbrevia. i'm creating archive with Jedi and extract it with TPabbrevia because Jedi does not work to extract tar archive on Windows 10 properly.

    Parameter archiveFileName should contain .tar file extension.

    function createArchiveFromDirectory(archiveFileName, directory:String):Boolean;
    var
      AFormat: TJclCompressArchiveClass;
      Arc: TJclCompressArchive;
      Code: Integer;
      str:string;
    begin
      Result := True;
      try
        AFormat := GetArchiveFormats.FindCompressFormat(archiveFileName);
        if ( AFormat <> nil )  then
          Begin
            FArchive := AFormat.Create(ArchiveFileName, 0, False);
            str := ExtractFileName(Directory);
            (FArchive as TJclCompressArchive).AddDirectory(str, Directory, True, True);
            (FArchive as TJclCompressArchive).Compress;
          End;
      except
        // exception handling
      end;
      FreeAndNil(FArchive);
    end;