login about faq

Hi,

i have trouble finding out, how to add a file to a zip in ObectiveC / iOS and assigning it another name.

it seems the only way to add a single file is [zipObj AppendOneFileOrDir:sourceFileURL.path saveExtraPath: NO] -- but doesn't allow new names..

any help is very welcome.

Thx, NR.

asked Oct 07 '13 at 12:48

Nabil%20Redmann's gravatar image

Nabil Redmann
11224


After a successful call to AppendOneFileOrDir, the zip object contains one additional entry, and that entry will be the very last one. The index of the last entry is zip.NumEntries - 1 (because the 1st entry is at index 0).

After calling AppendOneFileOrDir, you may get the CkoZipEntry object by calling zip.GetEntryByIndex(zip.NumEntries-1). Then update the zipEntry.Filename property to the other name.

Remember, the zip.Append methods don't actually write to the zip archive. The zip archive is only written when the WriteZip / WriteZipAndClose methods are called. The Append methods only add entries to the zip object. When files are appended, each entry contains a reference to the full path of the file (or directory) on disk, as well as the path to be used for the entry within the zip when written. Updating the zipEntry.Filename updates the path to be stored within the zip when writing, but does not change the path of the file on disk that is referenced.

link

answered Oct 08 '13 at 08:04

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

for others using this:

if ([zip AppendOneFileOrDir: ... ]) 
{
  CkoZipEntry *entry = [zip GetEntryByIndex: [NSNumber numberWithInt: [[zip NumEntries] integerValue] -1 ]];
  [entry setFileName: @"new_name.ext"];

  [zip WriteZipAndClose];
}
link

answered Oct 08 '13 at 09:14

Nabil%20Redmann's gravatar image

Nabil Redmann
11224

Thanks Nabil!

(Oct 08 '13 at 09:17) chilkat ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×87

Asked: Oct 07 '13 at 12:48

Seen: 965 times

Last updated: Oct 08 '13 at 09:17

powered by OSQA