I’m working on a Flask app to return a zip file to a user of a directory (a bunch of photos) but I don’t want to include my server directory structure in the returned zip. Currently, I have this : This works great for creating and returning the zip but the file includes the structure of my server i.e. In
Tag: python-zipfile
How can I open a folder with argparse
I want to open a folder containing x zipfiles. I have this code: But I get error code: PermissionError: [Errno 13] Permission denied: ‘Test’ I would like the zipfiles in the folder to be listed in an array when I run the code. Answer I’m not sure why you’re getting a permission error, but using open on a directory won’t
ValueError: write() requires mode ‘w’, ‘x’, or ‘a’ in Python zipfile
I am trying to open a specific file in the archive and then write some content to it. I am using the zipfile.open() function to get access to the file: However, it gives me a warning about duplicate file called ‘hello.txt’. After that I get the following error: What am I doing wrong here? My full traceback: Answer Right now
How to temporarily re-name a file or Create a re-named temp-file in Python before zipping it
In the below code I am trying to zip a list list of files, I am trying to rename the files before zipping it. So the file name will be in a more readable format for the user. It works for the first time, but when I do it again It fails with the error the file name already exists
How to avoid subfolders creation while zipping files?
I am trying to zip the files from the list localpath_list in to one zip file `reports.zip. It works as expected, but when I extract the reports.zip file, there are folders created inside it. i.e all the .xls files are under files/sample/. what I need is just the .xls files without any folder structure. Answer According to: [Python.Docs]: zipfile –
How to obtain path from ZipFile objects that could be passed into OpenCV?
I would like to pass the image file into OpenCV to create a NumPy array without unzipping it. My code looks like this: The place where I put a * is what I’m not sure what to pass in. I have created a few variables of class Pillow Image (pil_img), and ZipFileExt (zip_img). I understand that cv2.imread only accepts a
How to avoid zipfile error with python-pptx saving files
I am using the python-pptx package to create a number of .pptx files from a series of dataframes. All works well with adding slides and such until it comes time to call prs.save() where “prs” is the Presentation. Doing so leads to a zipfile error re: open handles needing to be closed. I have done some research on the history
Python zipfile does not unzip folders for windows zip archive
I have a zip file which was created on Windows machine using this tool System.IO.Compression.ZipFile (this zip archive contains many files and folders). I have a python code that runs on Linux machine (raspberry pi to be exact) which has to unzip the archive and create all the necessary folders and files. I’m using Python 3.5.0 and zipfile library, this
Using openpyxl module to write to spreadsheet creates a damaged spreadsheet, how to fix with zipfile module?
I have a program which writes to a spreadsheet using openpyxl. Upon execution of the program, the cells are filled as expected but the spreadsheet becomes damaged. Excel repairs the spreadsheet and I can then view it again. I have tried using the Open XML SDK Productivity Tool from Microsoft to compare a good and bad file with each other
How to know the folder size in a zipfile
I know that you can get the size in bytes of a file in a ZIP file using the .file_size method But is there any what I can get the size of a folder instead? Ex: Answer