zipfile

Unzip file from zip archive of multiple files using ZipFile class

那年仲夏 提交于 2019-12-18 17:25:38
问题 I'd like to use the ZipFile class to unzip a file using its name from an archive of multiple files. How can I get the string of the zip file name and directory to pass to the ZipFile constructor? 回答1: You can use the AssetManager and ZipInputStream http://developer.android.com/reference/android/content/res/AssetManager.html ZipInputStream in = null; try { final String zipPath = "data/sample.zip"; // Context.getAssets() in = new ZipInputStream(getAssets().open(zipPath)); for (ZipEntry entry =

unzipping file results in “BadZipFile: File is not a zip file”

时光总嘲笑我的痴心妄想 提交于 2019-12-18 13:53:07
问题 I have two zip files, both of them open well with Windows Explorer and 7-zip. However when i open them with Python's zipfile module [ zipfile.ZipFile("filex.zip") ], one of them gets opened but the other one gives error " BadZipfile: File is not a zip file ". I've made sure that the latter one is a valid Zip File by opening it with 7-Zip and looking at its properties (says 7Zip.ZIP). When I open the file with a text editor, the first two characters are "PK", showing that it is indeed a zip

How do I archive multiple files into a .zip file using scala?

折月煮酒 提交于 2019-12-18 00:04:53
问题 Could anyone post a simple snippet that does this? Files are text files, so compression would be nice rather than just archive the files. I have the filenames stored in an iterable. 回答1: There's not currently any way to do this kind of thing from the standard Scala library, but it's pretty easy to use java.util.zip: def zip(out: String, files: Iterable[String]) = { import java.io.{ BufferedInputStream, FileInputStream, FileOutputStream } import java.util.zip.{ ZipEntry, ZipOutputStream } val

Installed .Net 4.5 but can't use ZipFile class in Visual C#

不羁岁月 提交于 2019-12-17 18:46:32
问题 I'm kind of a newbie to Visual Studio programming. I recently upgraded .Net 4.0 to 4.5 in order to use the ZipFile class under System.IO.Compression, but after the installation completed, Visual Studio (I'm using 2012) still cannot recognize ZipFile as a class name. I've made sure that .Net 4.5 appears in Control Panel programs list and my C# solution sets .Net Framework 4 as the target framework. Could someone help me figure this out? 回答1: See ZipFile Class on MSDN. It shows the required

Extracting a zipfile to memory?

99封情书 提交于 2019-12-17 10:38:17
问题 How do I extract a zip to memory? My attempt (returning None on .getvalue() ): from zipfile import ZipFile from StringIO import StringIO def extract_zip(input_zip): return StringIO(ZipFile(input_zip).extractall()) 回答1: extractall extracts to the file system, so you won't get what you want. To extract a file in memory, use the ZipFile.read() method. If you really need the full content in memory, you could do something like: def extract_zip(input_zip): input_zip=ZipFile(input_zip) return {name:

How do I set permissions (attributes) on a file in a ZIP file using Python's zipfile module?

你说的曾经没有我的故事 提交于 2019-12-17 07:26:34
问题 When I extract files from a ZIP file created with the Python zipfile module, all the files are not writable, read only etc. The file is being created and extracted under Linux and Python 2.5.2. As best I can tell, I need to set the ZipInfo.external_attr property for each file, but this doesn't seem to be documented anywhere I could find, can anyone enlighten me? 回答1: This seems to work (thanks Evan, putting it here so the line is in context): buffer = "path/filename.zip" # zip filename to

Extracting .zip in python

故事扮演 提交于 2019-12-14 02:36:52
问题 I got BadZipfile: Bad magic number for file header error while extracting a .zip using python2 zipfile.ZipFile Same .zip when extracted with unzip gives file #1: bad zipfile offset (local header sig): 0 but gets extracted with exit code 2. When using jar -xf file.zip the command completes with $? == 0 with nothing being extracted. Using file gives: file -i file.zip file.zip application/octet-stream; charset=binary This gives incorrect header for zipfile $ hexdump -C file.zip | head -10

In Memory Zip File Python Error

偶尔善良 提交于 2019-12-13 19:25:14
问题 I'm trying to make an in-memory zip file in Python and upload it to Amazon S3. I've read the similar posts on the matter, but no matter what I try, Windows and Linux (RHEL5) cannot open it (it's corrupt). Here's the code I'm running: f_redirects = StringIO() f_links = StringIO() f_metadata = StringIO() # Write to the "files" zip_file = StringIO() zip = zipfile.ZipFile(zip_file, 'a', zipfile.ZIP_DEFLATED, False) zip.writestr('redirects.csv', f_redirects.getvalue()) zip.writestr('links.csv', f

Python zip a sub folder and not the entire folder path

ぐ巨炮叔叔 提交于 2019-12-13 11:41:34
问题 I have a program to zip all the contents in a folder. I did not write this code but I found it somewhere online and I am using it. I intend to zip a folder for example say, C:/folder1/folder2/folder3/ . I want to zip folder3 and all its contents in a file say folder3.zip. With the below code, once i zip it, the contents of folder3.zip wil be folder1/folder2/folder3/and files. I do not want the entire path to be zipped and i only want the subfolder im interested to zip (folder3 in this case).

Open a zip file and stream the xml file inside of the zip file

人走茶凉 提交于 2019-12-13 08:37:19
问题 I am trying to open bulk data from the USPTO. The xml files within the zips are concatenated xml files containing multiple xml declarations and are quiet large. I am trying to only read lines from the xml until i get to the next xml declaration. I found this related question, without code. What I want to create is a function that does the following: For each *.zip file Extract all xml file(s) (or open xml file(s) for reading) Read lines from the xml file(s) Append each line until the next xml