I am trying to zip a directory using python zipfile module and its working well.But now i want to exclude some folders.ie if my director tree is like then i want to archive all to myfile.zip but excluding “ghi” I am trying to zip files using so this is archiving everything under “D:review docs” to “Application server.zip” but i want
Tag: python-zipfile
Python zipfile compress_size returns ‘int’ object is not callable
I am trying to get the compressed size of a file with Python and zipfile I get the error What is the reason for that? Answer ZipInfo.compress_size is a simple int attribute, not a method, so you just need to do BTW, it’s a Bad Idea to use zip as the name of a variable, as it’s the name of
How to send a dynamically generate zipfile to the client
I am looking for a way to send a zipfile to the client that is generated from a requests response. In this example, I send a JSON string to a URL which returns a zip file of the converted JSON string. But my zip file is empty and the error returned by flask is Answer You should return the file
ZipFile does not store any text inside an archived file
The following code results in the file found in the zip being empty, instead of having some text in it: Answer Add flush to the file object: This problem also affects normal (non-temporary) files, so they’ll also need the flush treatment: Alternatively, de-denting the 2nd with block would avoid having to use flush since a file gets closed automatically when
Python zipfile module doesn’t compress files
I have a problem with compression in Python. I know I should call the ZIP_DEFLATED method when writing to make the zip file compressed, but it does not work for me. I have 3 PDF documents in the C:zip directory. When I run the following code it works just fine: It makes the test.zip file without the compression. When I
Faster alternative to Python’s zipfile module?
Is there a noticeably faster alternative to Python 2.7.4 zipfile module (with ZIP_DEFLATED) for zipping a large number of files into a single zip file? I had a look at czipfile https://pypi.python.org/pypi/czipfile/1.0.0, but that appears to be focused on faster decrypting (not compressing). I am routinely having to process a large number of image files (~12,000 files of a combination
Opening zipfile of unsupported compression-type silently returns empty filestream, instead of throwing exception
Seem to be knocking my head off a newbie error and I am not a newbie. I have a 1.2G known-good zipfile ‘train.zip’ containing a 3.5G file ‘train.csv’. I open the zipfile and file itself without any exceptions (no LargeZipFile), but the resulting filestream appears to be empty. (UNIX ‘unzip -c …’ confirms it is good) The file objects returned
Is python zipfile thread-safe?
In a django project, I need to generate some pdf files for objects in db. Since each file takes a few seconds to generate, I use celery to run tasks asynchronously. Problem is, I need to add each file to a zip archive. I was planning to use the python zipfile module, but different tasks can be run in different
Bad magic number error with ZipFile module in Python
I am using Python 2.7 on Windows 7 (64 bit). When I try to unzip a zip file with ZipFile module I get the following error:- WinRAR could extract the file I am trying to extract just fine. Here is the code I used to extract files from myzip.zip This code is working fine for many other zip files I
How can I pass a Python StringIO() object to a ZipFile(), or is it not supported?
I have a StringIO() file-like object, and I am trying to write it to a ZipFile(), but I get this TypeError: Here is a sample of the code I am using: The docs say that StringIO() is a file-like class and that ZipFile() can accept a file-like object. Is there something I am missing? Answer To add a string to