tags:

views:

282

answers:

1

I am trying to create a 7z archive of certain files using Delphi 2009.

The code below seems to work, but all of the items in the resulting 7z file are of zero size. All of the file names that are in the archive are correct, but they shouldn't be zero size.

How can I add files properly to a 7z archive using JCLCompression?

var
  fname, archiveFileName: string;
  arch: TJclUpdateArchive;
  archiveclass: TJCLUpdateArchiveClass;
  sr: TSearchRec;
begin
  fname := GetDesktop + 'Support.7z';

  archiveclass := GetArchiveFormats.FindUpdateFormat(fname);

  if not Assigned(archiveclass) then
    raise Exception.Create('Could not determine the Format of ' + fname);

  arch := archiveclass.Create(fname);
  try
    with arch do
    begin

      if FindFirst(uFolder + '*.*', faAnyFile, sr) = 0 then
      begin
        repeat
          AddFile(ExtractFileName(sr.Name), sr.Name);
        until FindNext(sr) <> 0;

        FindClose(sr);
      end;

      Compress;
    end;
  finally
    arch.free;
  end;
end;
+4  A: 

Never, ever, having jused JCLCompression my answer may wel be totally wrong, but don't you have to specify the folder somewhere ? You are only adding the filenames.

Edelcom
You're right. I assumed that TSearchRec.Name included the path to the file, but it doesn't. Once I added the files using their full path, it worked great.
croceldon