mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-06 05:27:05 +00:00
how to change ZipEntry Name? #94
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@andyhebear commented on GitHub (Apr 28, 2016):
and how to change dir name in Zip? there has fast way?
@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.