add empty directory using zipfile?

Oren Tirosh oren-py-l at
Thu Jun 26 09:40:01 CEST 2003

On Thu, Jun 26, 2003 at 04:31:37AM +0000, JanC wrote:
> Tung Wai Yip <tungwaiyip at> schreef:
> > Can I add empty directory using zipfile? When I try to add a directory
> > it complains that it is not a file.
> ZIP files can't contain directories, only files and the paths to those 
> files.  A workaround might be to put an empty file in the directory.

ZIP files *can* contain directories. They are described as zero-length
files with some flag set.  I don't see any specific API for this in but I think that if you pass a ZipInfo record with the right
values to ZipFile.writestr it should probably work. Consult the 
documentation of the zip format or just create a zip containing an empty 
directory with any zip utility look at the ZipInfo using


More information about the Python-list mailing list