new feature: rename of folders

Sep 11, 2009 at 9:51 PM
Edited Sep 11, 2009 at 9:56 PM


I'm using the filename property to rename files and directories within a ZIP file.
I've learned that renaming a directory means to create the new folder in the zip file first, then to update each contained file and subdirectory entry in order to correct the new path and finally delete the old directory.
This takes quite a long time if you perform this action on 100 000 entries.

Therefore, a rename method should be added in one of the next DotNetZip version in order to accelerate the process.

Stephan Hofmann

Sep 11, 2009 at 10:28 PM

"a directory" within a zipfile is not a container object.  The data model used within a zip file does not store files within directories.  The entries are all stored in a flat namespace, regardless of the path.  The path associated to each entry in a zipfile, while it may contain slashes, does not imply the use of a segmented, hierarchical storage space within the zip file, in contrast to the path used for a file in a filesystem.    Therefore, to "rename a directory" in a zipfile is meaningless. 

Because there is no hierarchical storage model, renaming 100,000 files will not take less time if it is done within the library.  It will require 100,000 separate actions whether done within the library, as you suggest, or by the application. 

If you want to "rename a directory" within a zipfile, and that directory contains 100,000 entries, a better idea is to rename the directory in the filesystem, before you add it to the zipfile.  An alternative to renaming the directory in the filesystem, is to create a junction or symlink in the filesystem, specifying the name you want to be used within the zip file.  Then add the directory via its junction name into the zip file. 


Sep 11, 2009 at 11:20 PM
Edited Sep 11, 2009 at 11:27 PM


I have used an alernative approach by extracting the to be renamed directory into the filesystem, rename the filesystem folder, zippig the new folder and delete all entries in the library. But this takes much more time than my first approach (within the library).

My question was more related to having a method to modify all path names (in the flat namespace) of all files and subdirectories recursively if the folder will be changed. Even if there is no hierarchical storage space, the zip files normally will be used like "mirrors" of a real file system and you have already a property "IsDirectory" which represents something like a hierarchical information. So it make sense of having a rename method especially for "folders" (those entries with indicator IsDirectory=True) which modfies all paths of entries containing the folder path.