How to compress a folder and all of its sub directories and files into a zip file?

could ildg could.net at gmail.com
Tue Jun 28 03:29:15 EDT 2005


but the file is just stored,
and not compressed.

On 6/28/05, could ildg <could.net at gmail.com> wrote:
> Thank you,
> it works~~
> 
> On 6/29/05, Peter Szinek <peter at rt.sk> wrote:
> > Hi,
> >
> > What about this:
> >
> > import os,zipfile
> > from os.path import join
> >
> >
> > zip = zipfile.ZipFile("myzipfile.zip", 'w')
> > for root, dirs, files in os.walk('.'):
> >      for fileName in files:
> >          zip.write(join(root,fileName))
> > zip.close()
> >
> > Maybe it zips also the myzipfile.zip ;-)
> > Probably this is not needed, so an additional test (something like
> > fileName != 'myfile.zip' would be needed.
> >
> > HTH,
> > Peter
> >
> > could ildg wrote:
> > > I want to compress a folder and all of its sub files including empty folders
> > > into a zip file. what's the pythonic way to do this?
> > >
> > > Thanks in advance.
> >
> >
>



More information about the Python-list mailing list