c# - Zip Archive: Can I rename or move a ZipArchiveEntry? -


does .net ziparchive allow rename or move entries? it's not possible change name of ziparchiveentry once created. seems have copy stream of original ziparchiveentry newly ziparchiveentry changed name.

thanks martin

i don't know "move" mean, other rename entry. in regular disk file systems, "move" rename full path of file name has changed, not "leaf node" file name. in .zip archive, more explicit; "directory" or "folder" in archive exists virtue of entry having directory name in name (separated, of course, directory separator character). "move" same "rename".


far whether can rename things, no…with ziparchive, have create new entry copy of original, new name, , delete original.

code this:

static void renameentry(this ziparchive archive, string oldname, string newname) {     ziparchiveentry oldentry = archive.getentry(oldname),         newentry = archive.createentry(newname);      using (stream oldstream = oldentry.open())     using (stream newstream = newentry.open())     {         oldstream.copyto(newstream);     }      oldentry.delete(); } 

implemented extension method, above, can call this:

ziparchive archive = ...; open archive in "update" mode string oldname = ...,     newname = ...; // names initialized appropriate  archive.renameentry(oldname, newname); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -