zipfile

Rename file in zip with zip4j

末鹿安然 提交于 2019-12-11 04:53:44
问题 I'm using zip4j 1.3.1 to compress files in my application. Now I'm trying to rename the file inside the zip without having to rename the file itself. There seems to be a method for that, but it's not working. My code looks like: public static void zipFile(File dstPath, File srcFile, String optionalName) throws ZipException { ZipFile zipFile = new ZipFile(dstPath); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); parameters

Zipfile python module bytesize difference

好久不见. 提交于 2019-12-11 03:25:21
问题 I'm using zipfile module for python to extract a zipfile I retrieved from the internet using urllib.urlretrieve() the files in the zip file are patch files created by bsdiff, however when I let python extract the zip file and try to use bspatch it says corrupted patch file. When I manually extract the zip file using 7-zip overwrite the patch files and then run the patcher it patches fine. I also noticed when overwriting these files manually that the bytesize differed. One should be 195 bytes

Why is ZipFile.CreateFromDirectory throwing access denied here?

故事扮演 提交于 2019-12-11 02:07:50
问题 I'm suffering from a file access problem. The main problem is I can't write a ZipFile in a folder which is acquired by the Folder Picker. While I've been working on this project, until I encountered this ZipFile problem, I did lots of jobs associated with creating files, with deleting files, with creating folders in that folder. It doesn't seem to matter for this problem. As the file-access documentation says, I have access permission on a folder which is chosen by the user when using the

Unzipping with ZipInputStream never finishes

风流意气都作罢 提交于 2019-12-11 01:02:49
问题 I'm using an AsyncTask to unzip a file, and all seems to be going well (all the files in the ZIP archive are extracted), but my unzip method never finishes. Here's the source for my unzip class: public class MyUnzipper { public static boolean unzipFileIntoDirectory(String inputFilename, String outputPath) throws Exception { ZipInputStream zis = null; BufferedOutputStream dest = null; try { File archive = new File(inputFilename); File destinationDir = new File(outputPath); final int BUFFER

zipfile in Python produces not quite normal ZIP files

孤人 提交于 2019-12-10 19:53:11
问题 In my project set of files are created and packed to ZIP archive to be used at Android mobile phone. Android application is opening such ZIP files for reading initial data and then store results of its work to the same ZIPs. I have no access to source code of mentioned Android App and old script that generated zip files before (actually, I do not know how old ZIP files were created). But structure of ZIP archive is known and I have written new python script to make the same files. I was faced

Adding large files to IO.Compression.ZipArchiveEntry throws OutOfMemoryException Exception

梦想的初衷 提交于 2019-12-10 17:23:26
问题 I am trying to add a large video file(~500MB) to an ArchiveEntry by using this code: using (var zipFile = ZipFile.Open(outputZipFile, ZipArchiveMode.Update)) { var zipEntry = zipFile.CreateEntry("largeVideoFile.avi"); using (var writer = new BinaryWriter(zipEntry.Open())) { using (FileStream fs = File.Open(@"largeVideoFile.avi", FileMode.Open)) { var buffer = new byte[16 * 1024]; using (var data = new BinaryReader(fs)) { int read; while ((read = data.Read(buffer, 0, buffer.Length)) > 0) {

How to print the percentage of zipping a file python

爱⌒轻易说出口 提交于 2019-12-10 13:15:16
问题 I would like to get the percentage a file is at while zipping it. For instance it will print 1%, 2%, 3%, etc. I have no idea on where to start. How would I go about doing this right now I just have the code to zip the file. Code: zipPath = zipfile.ZipFile("Files/Zip/" + pic + ".zip", "w") for root, dirs, files in os.walk(filePath): for file in files: zipPath.write(os.path.join(root, file), str(pic) + "\\" + file) print("Done") zipPath.close() 回答1: Unfortunately, you can't get progress on the

Python--reading password protected Word Documents with zipfile

爷,独闯天下 提交于 2019-12-10 10:44:40
问题 I am trying to read a password protected word document on Python using zipfile. The following code works with a non-password protected document, but gives an error when used with a password protected file. try: from xml.etree.cElementTree import XML except ImportError: from xml.etree.ElementTree import XML import zipfile psw = "1234" WORD_NAMESPACE = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}' PARA = WORD_NAMESPACE + 'p' TEXT = WORD_NAMESPACE + 't' def get_docx_text(path)

How to compress csv file into zip archive directly?

可紊 提交于 2019-12-10 03:07:13
问题 I am generating a number of csv files dynamically, using the following code: import csv fieldnames = ['foo1', 'foo2', 'foo3', 'foo4'] with open(csvfilepath, 'wb') as csvfile: csvwrite = csv.DictWriter(csvfile, delimiter=',', fieldnames=fieldnames) csvwrite.writeheader() for row in data: csvwrite.writerow(row) To save space, I want to compress them. Using the gzip module is quite easy: with gzip.open("foo.gz", "w") as csvfile : csvwrite = csv.DictWriter(csvfile, delimiter=',', fieldnames

How to check if a zip file is encrypted using python's standard library zipfile?

让人想犯罪 __ 提交于 2019-12-10 02:09:38
问题 I am using python's standard library, zipfile, to test an archive: zf = zipfile.ZipFile(archive_name) if zf.testzip()==None: checksum_OK=True And I am getting this Runtime exception: File "./packaging.py", line 36, in test_wgt if zf.testzip()==None: checksum_OK=True File "/usr/lib/python2.7/zipfile.py", line 844, in testzip f = self.open(zinfo.filename, "r") File "/usr/lib/python2.7/zipfile.py", line 915, in open "password required for extraction" % name RuntimeError: File xxxxx/xxxxxxxx.xxx