how to change ZipEntry Name? #94

Closed
opened 2026-01-29 22:06:28 +00:00 by claunia · 2 comments
Owner

Originally created by @andyhebear on GitHub (Apr 28, 2016).

how to change ZipEntry Name?
ZipArchive za=ZipArchive.Open("test.zip");
string oldName="zt/test_old.txt";
string newName="zt2/test.txt";
SharpCompress.Archive.Zip.ZipArchiveEntry findfile=null;
foreach (var ze in za.Entries) {
if (ze.IsDirectory) continue;
if (string.Compare(ze.Key, oldName) == 0) {
findfile = ze;
break;
}
}
if (findfile != null) {
MemoryStream ms=GetUnCompressStream(findfile);
za.AddEntry(newName, ms,true,ms.Length,findfile.LastModifiedTime);
za.RemoveEntry(findfile);
findfile.Close();
}

this method is Unfriendly.

And consumes a lot of performance.

Originally created by @andyhebear on GitHub (Apr 28, 2016). how to change ZipEntry Name? ZipArchive za=ZipArchive.Open("test.zip"); string oldName="zt/test_old.txt"; string newName="zt2/test.txt"; SharpCompress.Archive.Zip.ZipArchiveEntry findfile=null; foreach (var ze in za.Entries) { if (ze.IsDirectory) continue; if (string.Compare(ze.Key, oldName) == 0) { findfile = ze; break; } } if (findfile != null) { MemoryStream ms=GetUnCompressStream(findfile); za.AddEntry(newName, ms,true,ms.Length,findfile.LastModifiedTime); za.RemoveEntry(findfile); findfile.Close(); } this method is Unfriendly. And consumes a lot of performance.
Author
Owner

@andyhebear commented on GitHub (Apr 28, 2016):

and how to change dir name in Zip? there has fast way?

@andyhebear commented on GitHub (Apr 28, 2016): and how to change dir name in Zip? there has fast way?
Author
Owner

@adamhathcock commented on GitHub (Sep 27, 2016):

You can't change names without rebuilding the entire zip file.

I could probably change something to get around recompressing but that's a lot of work for a minor use-case. You're welcome to try with a PR.

@adamhathcock commented on GitHub (Sep 27, 2016): You can't change names without rebuilding the entire zip file. I could probably change something to get around recompressing but that's a lot of work for a minor use-case. You're welcome to try with a PR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#94