This project is read-only.

What is the best way to rename a file upon extraction from a zip

Feb 25, 2011 at 6:56 AM

Hi I'm looking for a way to rename a file upon extraction from a zip archive. I don't want to rename this file inside the zip.

Feb 27, 2011 at 6:02 PM
Edited Feb 27, 2011 at 6:02 PM

You have two options: Rename before you extract, or rename after you extract.

Renaming before extraction is a matter of setting the FileName property on the ZipEntry.   e.FileName = "new" followed by "e.Extract()" will extract the entry to the given name.

Renaming after extraction involves using the System.IO.File class and renaming the file that way. 

If you modify the FileName entry in the ZipEntry, and don't save the ZipFile - in other words if you don't call ZipFile.Save() , then the change you made is not made permanent in the zip file in the filesystem.   The change is made only to the in-memory instance of the ZipFile object, unless/until you call ZipFile.Save().


Mar 4, 2011 at 7:56 AM

Thanks! I've used a first option. And it works great.