T
Tung Wai Yip
Can I add empty directory using zipfile? When I try to add a directory
it complains that it is not a file.
tung
it complains that it is not a file.
tung
Tung Wai Yip said: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't contain directories, only files and the paths to those
files. A workaround might be to put an empty file in the directory.
Ben Finney said:A better solution might be to use tar (or cpio) for archiving, since
they can add directories as well as files, and can also preserve file
permissions from Unix filesystems.
You then get the benefit of choosing whatever compression method you
like for the resultant archive. gzip and bzip2 both offer superior
compression to the built-in compression for Zip.
Oren Tirosh said: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
zipfile.py 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 zipfile.py.
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
zipfile.py 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 zipfile.py.
Oren
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.