How do I zip the contents of a folder using python (version 2.5)?

Amara picture Amara · Nov 17, 2008 · Viewed 25.6k times · Source

Once I have all the files I require in a particular folder, I would like my python script to zip the folder contents.

Is this possible?

And how could I go about doing it?

Answer

jb. picture jb. · Aug 9, 2012

On python 2.7 you might use: shutil.make_archive(base_name, format[, root_dir[, base_dir[, verbose[, dry_run[, owner[, group[, logger]]]]]]]).

base_name archive name minus extension

format format of the archive

root_dir directory to compress.

For example

 shutil.make_archive(target_file, format="bztar", root_dir=compress_me)