difficult zipefile Question

Dan Perl danperl at rogers.com
Wed Oct 6 18:43:49 EDT 2004


I may be wrong, and I may have to eat my words later, but I think that the 
zip file format does not handle empty folders.  I tried it myself with 
winzip just a few days ago.  I think that zip only keeps a list of files 
with their path so the folder will not be stored in the zip file if there is 
no file in that folder.  Like I already said, I may be wrong, but I would 
recommend that you use tarfile instead.

Dan

"matthiasjanes" <matthiasjanes at gmx.net> wrote in message 
news:d588131f.0410061437.4ecda4bf at posting.google.com...
> hello all,
>
> i want to zip a folder plus the files and subfolders.
>
> which works something like that:
>
> #sample code
>
> import os, zipfile
>
> def zipit(path, ziper):
>
>  for root, dirs, files in os.walk(path):
>
>    for anyFile in files:
>
>      fullname = os.path.join(root, anyFile)
>
> if __name__ == '__main__':
>
>  ziper = zipfile.ZipFile('test.zip', 'w')
>  zipit('somefolderTozip', ziper)
>  ziper.close()
> #____________________________
>
>
> this works fine as long as there is no empty subfolder.
>
> can anyone tell me - or better give me a small example of code how to
> add an empty folder to the zip archive.
>
> thanks mr. janes 





More information about the Python-list mailing list