Unfortunately, you cannot make progress in compressing each individual file from the zipfile module, but you can get an idea of ββthe overall progress by keeping track of how many bytes you have processed so far.
As Mikko Ortamaa suggested, the easiest way to do this is to double-view the list of files, first determine the file sizes, and then perform the compression. However, as Kevin said, the contents of the directory may change between these two passes, so the numbers may not be accurate.
The program below (written for Python 2.6) illustrates the process.
Note that I am opening a zip file with the argument zipfile.ZIP_DEFLATED compression; zipfile.ZIP_STORED used by zipfile.ZIP_STORED , that is, compression is not performed. In addition, zip files can work with both DOS-style path separators and Unix-style ones, so you don't need to use backslashes in your archive paths, and as my code shows, you can just use os.path.join() to create the path to the archive file.
By the way, in your code you have str(pic) inside the inner for loop. In general, this is a slightly wasteful reevaluation of a function with a constant argument inside a loop. But in this case, this is completely superfluous, since from your first statement it seems that pic already a string.
source share