EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Renaming Zip entry

Posted: 11/05/2013 09:05:21
by David Eršil (Standard support level)
Joined: 01/15/2013
Posts: 38


I would like to ask if there is an easy way to rename an entry in a zip archive using TElZipReader/TElZipWriter class (with WP75 binaries) - I mean without deleting the former entry and adding a new one.

Thank you very much.
Posted: 11/05/2013 09:15:21
by Vsevolod Ievgiienko (Team)


You can simply change TElZipArchiveDirectoryEntry.FileName property.
Posted: 11/05/2013 09:40:53
by David Eršil (Standard support level)
Joined: 01/15/2013
Posts: 38

Hi Vsevolod,

thank you for your quick response. This is what I have already tried, but with no luck.

I am able to find the entry, but when I change its name and recompress the archive, the name is still the same (although oldName and newName are obviously different).

Following is a simplified piece of code that I use - can you see anything odd in it that I can't?

Z = (await zip.OpenAsync(FileAccessMode.ReadWrite)).AsStream();

if (!zipWriter.Opened)
   zipWriter.Password = this.mStorePass;

TElZipArchiveDirectoryEntry de = zipWriter.Directory.EntryWithName(oldName);
if (de != null)
   //here I intentionally do not change the variable, but the entry itself
   zipWriter.Directory.EntryWithName(oldName).FileName = newName;
   await Z.FlushAsync();

Posted: 11/05/2013 09:56:53
by Eugene Mayevski (Team)

Let's determine, what exactly you want to do -- do you want to open the existing archive, rename the file and write back the directory? Or you want to rename the file when the archive is prepared (not yet saved)?

Sincerely yours
Eugene Mayevski
Posted: 11/05/2013 10:04:17
by David Eršil (Standard support level)
Joined: 01/15/2013
Posts: 38

The first option is what I need - I already have an existing (saved) with a few entries. I want to open it, find the specified entry, change its name and save the change.

Thanks for your assistance.
Posted: 11/05/2013 10:36:20
by Eugene Mayevski (Team)

I am not sure that this scenario is possible. I'll need to check this with developers tomorrow.

Sincerely yours
Eugene Mayevski
Posted: 11/05/2013 14:22:39
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 442

This is not easily possible - entries in ZIP archive are written one after other, and if you'll change the file name (given that it is not the case when the length of the file name is the same), you'll need to somehow reorder entries in archive. And, actually, with ElPGPReader/ElPGPWriter it is not possible at the moment without deleting/re-adding entry to archive.
Posted: 11/06/2013 01:51:44
by David Eršil (Standard support level)
Joined: 01/15/2013
Posts: 38

Ok, never mind, I will go the remove-reinsert way. I just wanted to be sure and not to reinvent the wheel :)

Thank you both for your help!

David Eršil



Topic viewed 800 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!