zipfile

python zipfile module doesn't seem to be compressing my files

拜拜、爱过 提交于 2019-11-28 06:09:00
I made a little helper function: import zipfile def main(archive_list=[],zfilename='default.zip'): print zfilename zout = zipfile.ZipFile(zfilename, "w") for fname in archive_list: print "writing: ", fname zout.write(fname) zout.close() if __name__ == '__main__': main() The problem is that all my files are NOT being COMPRESSED! The files are the same size and, effectively, just the extension is being change to ".zip" (from ".xls" in this case). I'm running python 2.5 on winXP sp2. This is because ZipFile requires you to specify the compression method. If you don't specify it, it assumes the

How to unzip a file with Python 2.4?

こ雲淡風輕ζ 提交于 2019-11-28 05:48:27
I'm having a hard time figuring out how to unzip a zip file with 2.4. extract() is not included in 2.4. I'm restricted to using 2.4.4 on my server. Can someone please provide a simple code example? You have to use namelist() and extract() . Sample considering directories import zipfile import os.path import os zfile = zipfile.ZipFile("test.zip") for name in zfile.namelist(): (dirname, filename) = os.path.split(name) print "Decompressing " + filename + " on " + dirname if not os.path.exists(dirname): os.makedirs(dirname) zfile.extract(name, dirname) There's some problem with Vinko's answer (at

Read directly a file within a Zip file - Java

萝らか妹 提交于 2019-11-28 04:19:44
问题 My situation is that I have a zip file that contains some files (txt, png, ...) and I want to read it directly by their names, I have tested the following code but no result (NullPointerExcepion): InputStream in = Main.class.getResourceAsStream("/resouces/zipfile/test.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); resources is a package and zipfile is a zip file. 回答1: If you can be sure that your zip file will never be packed inside another jar, you can use

How to read content of the Zipped file without extracting in java

懵懂的女人 提交于 2019-11-28 01:15:14
问题 I have file with names like ex.zip . In this example, the Zip file contains only one file with the same name(ie. `ex.txt'), which is quite large. I don't want to extract the zip file every time.Hence I need to read the content of the file(ex.txt) without extracting the zip file. I tried some code like below But i can only read the name of the file in the variable. How do I read the content of the file and stores it in the variable? Thank you in Advance fis=new FileInputStream("C:/Documents

Unzip and save files using as3?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 01:13:47
I have a list of zip and rar files in a local folder. All I need to do is to extract the contents of the zip as well as rar files and to save them in a folder with the same name of the respective archive file. Since I am new to as3, I have no clue for this. Is there any Library for this??? Thanks in advance... There are a few libraries out there that deal with ZIP files in as3, but beware that this is no easy task for a beginner in ActionScript 3. FZip seems to be the most widely used, but it requires that the ZIP archives have Adler32 checksums . Provided with the library there is a Python

How do I add files to an existing zip archive

会有一股神秘感。 提交于 2019-11-27 22:57:31
How can I add some file (almost always a single .csv file) to an existing zip file? Since you are in .NET 4.5, you can use the ZipArchive (System.IO.Compression) class to achieve this. Here is the MSDN documentation: ( MSDN ). Here is their example, it just writes text, but you could read in a .csv file and write it out to your new file. To just copy the file in, you would use CreateFileFromEntry , which is an extension method for ZipArchive . using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open)) { using (ZipArchive archive = new ZipArchive(zipToOpen

How to update one file inside zip file using python [duplicate]

痴心易碎 提交于 2019-11-27 20:35:21
问题 This question already has an answer here: overwriting file in ziparchive 2 answers I have this zip file structure. zipfile name = filename.zip filename> images> style.css default.js index.html I want to update just index.html. i tried to update index.html, but then it contains only index.html file in 1.zip file and other files are remobved. This is the code which i tried: import zipfile msg = 'This data did not exist in a file before being added to the ZIP file' zf = zipfile.ZipFile('1.zip',

seek() a file within a zip file in Python without passing it to memory

前提是你 提交于 2019-11-27 18:05:48
问题 is there anyway to make a file inside a zip file seekable in Python without reading it to memory? I tried the obvious procedure but I get an error since the file is not seekable: In [74]: inputZipFile = zipfile.ZipFile("linear_g_LAN2A_F_3keV_1MeV_30_small.zip", 'r') In [76]: inputCSVFile = inputZipFile.open(inputZipFile.namelist()[0], 'r') In [77]: inputCSVFile Out[77]: <zipfile.ZipExtFile at 0x102f5fad0> In [78]: inputCSVFile.se inputCSVFile.seek inputCSVFile.seekable In [78]: inputCSVFile

Adding folders to a zip file using python

ぐ巨炮叔叔 提交于 2019-11-27 17:58:42
I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder. So I want to end up with a zip file with a single folder with files in. I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject. I started out with this: def addFolderToZip(myZipFile,folder): folder = folder.encode('ascii') #convert path to ascii for ZipFile Method for file in glob.glob(folder+"/*"): if os.path.isfile(file): print file myZipFile.write(file, os.path.basename(file), zipfile.ZIP_DEFLATED) elif os.path.isdir(file):

Progress Bar not available for zipfile? How to give feedback when program seems to hang

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:24:31
I am fairly new to C# and coding in general so some of this might be going about things the wrong way. The program I wrote works and compresses the file as expected, but if the source is rather large, the program appears (to Windows) to hang. I feel like I should be using a Thread but I am not sure that will help. I would use a progress bar but the 'new' (.net 4.5) library for zipfile from System.IO.Compression which replaced Ionic.Zip.ZipFile does not have a method to report progress? Is there a way around this? Should I be using a Thread ? or DoWork ? The trouble is that the user and the