how to zip similar files using python?

How can I archive files using the Zip function in Python?

  • I created a source to make a back-up and a destination directory to store them.What I want is to back up the files in Zip format to the specified destination directory using a Python script. So how could I implement it in Python using the Zip function? One suggestion I got is to download http://gnuwin32.sourceforge.net/packages/zip.htm and install it. I installed the software but I'm unable to create a backup. I want to do it automatically by the system using the os.system() command. Please help.

  • Answer:

    You could lookup how to create a zip file with zip tool via command line and call that command with the help of os.system() or you could use the zip python module. For example i use 7zip, which can be downloaded from http://www.7-zip.org. After installing lookup how to create zip file via commandline http://linux.die.net/man/1/7z. Make sure that the 7zip is in your environment variable http://en.wikipedia.org/wiki/PATH_%28variable%29 . And you can call the zip command with the https://docs.python.org/2/library/os.html#os.system in your python script. Or you could just read up http://pymotw.com/2/zipfile/ and do it yourself. I suggest the latter method.

Hariharan Rangasamy at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.