i zipped all the files using shutil .make_archive("arch", "zip", path) and want know whether all the files are zipped.I used the below code to zip the files.

shutil.make_archive("arch", "zip", r"path")

3 Answers

Sam Mason On Best Solutions

as pointed out by Kevin/others, in Python (and as most languages with "exception handling") you can expect that most routines will raise/throw an exception on error conditions

if you care about the details, the relevant Python source is in shutil and zipfile where you can see that they use appropriate "context managers" and raise exceptions as appropriate, but mostly rely on lower level file operations to throw

if you want some human output to monitor progress, you can use the logging infrastructure, e.g.:

import logging

shutil.make_archive("arch", "zip", "path", logger=logging)

(see the tutorial for more details) will cause it to give more output

Viper On

I don't understand why would you want to do that ? If make_archive did not raises any exceptions, all files in path are supposed to be in arch.

If you want to know it anyway, you can either :

  • unzip the archive with shutil.unpack_archive

  • use zipfile to read the archive like this :

    from ZipFile import ZipFile

    with ZipFile("arch.zip") as myzip:

SmrtGrunt On

Example 3 at this link seems to indicate that shutil.make_archive returns a string with the path and file name of the file that was created. It shows that string being used to check the newly created archive.