Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using python to "zip" a directory

Status
Not open for further replies.

bdowen

Programmer
Jun 10, 2003
12
US
I am new to Python programming but have made considerable progress in the last week.

I need to know if it is possible and how if it is, to zip the contents of a directory using python. I have tried to call winzip using os.system, but have run into some challenges. I would like to make my program portable so I would rather use some of pythons built it functions if possible. The gzip module seemed promising but from what I have seen it is only good for files, not directories and all of its contents.

Help would be appreciated if anyone out there has encountered the same thing or knows the answer.
 
There is (or was) a zip file class. See
James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Thanks for the help!!! I actually found a round about way of doing it. I am just learning classes. There is a function in distutils.archive_util called make_zipfile. Turns out this is a very simple way to zip a directory and all its contents. Receives the location of the directory to be zipped and the location to put it.

Thanks again for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top