Unzipping files in Python
import zipfile with zipfile.ZipFile(path_to_zip_file, ‘r’) as zip_ref: zip_ref.extractall(directory_to_extract_to) That’s pretty much it!
import zipfile with zipfile.ZipFile(path_to_zip_file, ‘r’) as zip_ref: zip_ref.extractall(directory_to_extract_to) That’s pretty much it!
To expand upon Steven Penny’s PowerShell solution, you can incorporate it into a batch file by calling powershell.exe like this: powershell.exe -nologo -noprofile -command “& { Add-Type -A ‘System.IO.Compression.FileSystem’; [IO.Compression.ZipFile]::ExtractToDirectory(‘foo.zip’, ‘bar’); }” As Ivan Shilo said, this won’t work with PowerShell 2, it requires PowerShell 3 or greater and .NET Framework 4.
Make sure your jar file is not corrupted. If it’s corrupted or not able to unzip, this error will occur.
I created a simple library to create a password encrypted zip file in python. – here import pyminizip compression_level = 5 # 1-9 pyminizip.compress(“src.txt”, “dst.zip”, “password”, compression_level) The library requires zlib. I have checked that the file can be extracted in WINDOWS/MAC.
To build a .tar.gz (aka .tgz) for an entire directory tree: import tarfile import os.path def make_tarfile(output_filename, source_dir): with tarfile.open(output_filename, “w:gz”) as tar: tar.add(source_dir, arcname=os.path.basename(source_dir)) This will create a gzipped tar archive containing a single top-level folder with the same name and contents as source_dir.
There are VBA methods to zip and unzip using the windows built in compression as well, which should give some insight as to how the system operates. You may be able to build these methods into a scripting language of your choice. The basic principle is that within windows you can treat a zip file … Read more
You can use popen() (docs) or proc_open() (docs) to execute a unix command (eg. zip or gzip), and get back stdout as a php stream. flush() (docs) will do its very best to push the contents of php’s output buffer to the browser. Combining all of this will give you what you want (provided that … Read more
Thanks to ZipArchive creates invalid ZIP file, I got: using (var memoryStream = new MemoryStream()) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { var demoFile = archive.CreateEntry(“foo.txt”); using (var entryStream = demoFile.Open()) using (var streamWriter = new StreamWriter(entryStream)) { streamWriter.Write(“Bar!”); } } using (var fileStream = new FileStream(@”C:\Temp\test.zip”, FileMode.Create)) { memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.CopyTo(fileStream); … Read more
The GZIP methods: public static byte[] compress(String string) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(string.length()); GZIPOutputStream gos = new GZIPOutputStream(os); gos.write(string.getBytes()); gos.close(); byte[] compressed = os.toByteArray(); os.close(); return compressed; } public static String decompress(byte[] compressed) throws IOException { final int BUFFER_SIZE = 32; ByteArrayInputStream is = new ByteArrayInputStream(compressed); GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE); … Read more
I know its late and there are lots of answers but this zip4j is one of the best libraries for zipping I have used. Its simple (no boiler code) and can easily handle password protected files. import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.core.ZipFile; public static void unzip(){ String source = “some/compressed/file.zip”; String destination = “some/destination/folder”; String password = … Read more