zipfile

Unzip all zipped files in a folder to that same folder using Python 2.7.5

寵の児 提交于 2019-12-03 03:58:44
问题 I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script import os, zipfile folder = 'D:/GISData/LiDAR/SomeFolder' extension = ".zip" for item in os.listdir(folder): if item.endswith(extension): zipfile.ZipFile.extract(item) However, when I run the script, I

Python and the zipfile module

烂漫一生 提交于 2019-12-02 19:31:17
问题 According to Python documentation: ZipFile.extract(member[, path[, pwd]]) Extract a member from the archive to the current working directory ; member must be its full name or a ZipInfo object). Its file information is extracted as accurately as possible. path specifies a different directory to extract to . member can be a filename or a ZipInfo object. pwd is the password used for encrypted files. I have large number of zipped files that each contain 1000 archived files in them. Using the

Create .zip in Python?

爷,独闯天下 提交于 2019-12-02 18:50:10
I'm trying to create a function in my script that zips the contents of a given source directory ( src ) to a zip file ( dst ). For example, zip('/path/to/dir', '/path/to/file.zip') , where /path/to/dir is a directory, and /path/to/file.zip doesn't exist yet. I do not want to zip the directory itself, this makes all the difference in my case. I want to zip the files (and subdirs) in the directory. This is what I'm trying: def zip(src, dst): zf = zipfile.ZipFile("%s.zip" % (dst), "w") for dirname, subdirs, files in os.walk(src): zf.write(dirname) for filename in files: zf.write(os.path.join

Zipping a file using DotNetZip on C# on mac

浪子不回头ぞ 提交于 2019-12-02 18:22:37
问题 I am trying to zip a file or directory in C# using the following snippet of code on a mac that uses DotNetZip. But I get some exceptions below, what am I doing wrong? using Ionic.Zip; namespace CSLab { class Program { static void Main(string[] args) { using (ZipFile zip = new ZipFile()) { zip.Password = "password"; zip.AddDirectory("./test"); zip.Save("a.zip"); } } } } Unhandled Exception: System.ArgumentException: 'IBM437' is not a supported encoding name. For information on defining a

How to delete a zip file using php

人走茶凉 提交于 2019-12-02 13:26:21
This is my php code to delete a zip file: $name = "zip_file_name"; chmod('./modules/',0777); unlink('./modules/'.$name.'.zip'); Here modules is the folder of zip file contained. When I wrote this code I got an error: <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> <p>Severity: Warning</p> <p>Message: unlink(./modules/texts.zip) [<a href='function.unlink'>function.unlink</a>]: Permission denied</p> <p>Filename: controllers/super_admin.php</p> <p>Line Number: 590</p> </div> If there is any mistake in my code? I also check the chmod

Python and the zipfile module

ぃ、小莉子 提交于 2019-12-02 11:36:06
According to Python documentation: ZipFile.extract(member[, path[, pwd]]) Extract a member from the archive to the current working directory ; member must be its full name or a ZipInfo object). Its file information is extracted as accurately as possible. path specifies a different directory to extract to . member can be a filename or a ZipInfo object. pwd is the password used for encrypted files. I have large number of zipped files that each contain 1000 archived files in them. Using the function above I can extract only the files that I need from each zipped archive: def getAIDlist(aidlist_to

Extract zip to memory, parse contents

非 Y 不嫁゛ 提交于 2019-12-02 10:57:58
问题 I want to read the contents of a zip file into memory rather than extracting them to disc, find a particular file in the archive, open the file and extract a line from it. Can a StringIO instance be opened and parsed? Suggestions? Thanks in advance. zfile = ZipFile('name.zip', 'r') for name in zfile.namelist(): if fnmatch.fnmatch(name, '*_readme.xml'): name = StringIO.StringIO() print name # prints StringIO instances open(name, 'r') # IO Error: No such file or directory... I found a few

Java: Zip file with non-static filename

南楼画角 提交于 2019-12-02 08:43:12
I found this ZipUtils class on this post: how to zip a folder itself using java I modified it so I could pass a zip file name. However, the only way it works is with a hardcoded static string. The zippedFile string is grabbed from the database. I have compared the dbZippedFile and hardcodedZippedFile and they are both identical... Perhaps there is an issue with using a non-static string with FileOutputStream? This problem only occurs when trying to zip directories (one file works fine). Does anyone know what I am doing wrong or have a good alternative? It never throws an error. It just fails

Eclipse, Java: How to import a library in zip-format?

你。 提交于 2019-12-02 08:11:27
Ok, this is basic, but it seems that the normal way of doing this doesn't work for me. I'm trying to import the jSSC library, for communication with serial ports etc. The newest library is jSSC-0.9.0-Release So, I've tried the following: Placed the zip file in the workspace and added it as "external jar" in the project properties -> java build path -> libraries. Then I try including something from the library: import jssc.SerialPortList; Error: The import jssc cannot be resolved Then I placed the zip file in a folder called /libs in the project root, and added it as "jar" (not external).

c# UnauthorizedAccessException when using ZipArchive but not ZipFile

北城余情 提交于 2019-12-02 07:37:34
问题 I am able to zip files from a specific folder using ZipFile.CreateFromDirectory in the following test code (I only used this code to test how zipping works): // Where the files are located string strStartPath = txtTargetFolder.Text; // Where the zip file will be placed string strZipPath = @"C:\Users\smelmo\Desktop\testFinish\" + strFileNameRoot + "_" + txtDateRange1.Text.Replace(@"/", "_") + "_" + txtDateRange2.Text.Replace(@"/", "_") + ".zip"; ZipFile.CreateFromDirectory(strStartPath,