zipfile

Getting “TypeError: pwd: expected bytes, got str” when extracting zip file with password

核能气质少年 提交于 2020-05-15 21:52:26
问题 I want to unzip a specific named file located in a specific directory. The name of the file = happy.zip . The location = C:/Users/desktop/Downloads . I want to extract all the files to C:/Users/desktop/Downloads (the same location) I tried: import zipfile import os in_Zip = r"C:/Users/desktop/Downloads/happy.zip" outDir = r"C:/Users/desktop/Downloads" z = zipfile.ZipFile(in_Zip, 'r') z.extractall(outDir, pwd='1234!') z.close But I got: "TypeError: pwd: expected bytes, got str" 回答1: In Python

Using openpyxl module to write to spreadsheet creates a damaged spreadsheet, how to fix with zipfile module?

*爱你&永不变心* 提交于 2020-05-14 18:23:05
问题 I have a program which writes to a spreadsheet using openpyxl . Upon execution of the program, the cells are filled as expected but the spreadsheet becomes damaged. Excel repairs the spreadsheet and I can then view it again. import openpyxl from openpyxl import load_workbook amounts, row = [1, 2, 3, 4, 5], 2 book = load_workbook("output.xlsx") sheet = book.active for i, value in enumerate(amounts): sheet.cell(column=i+1, row=row, value=value) print ("Sheet updating complete.") book.save(

Could not find function “zip.file.extract”

て烟熏妆下的殇ゞ 提交于 2020-04-07 06:48:10
问题 library(utils) a<-zip.file.extract("\\1\\1.csv",zipname="drivers.zip") Error: could not find function "zip.file.extract" What's going on? 回答1: zip.file.extract() is a defunct function as of R 2.14 (see ?"utils-defunct" help page or try brining up the ?zip.file.extract help page). Use the unzip() function instead. Perhaps unzip("drivers.zip", files="\1\1.csv") or you can omit the files= to extract all files in the zip archive to the current working directory. 来源: https://stackoverflow.com

System.IO.Compression.ZipFile .NET 4.5 output zip in not suitable for Linux/Mac/Java

我的梦境 提交于 2020-03-17 08:15:21
问题 While using .NET System.IO.Compression.ZipFile.CreateFromDirectory class the outcome zip is badly extracted on system with forward-slash directory separator. Reason: The zip contains backslash inside the names 回答1: To overcome this problem a workaround exists: class MyEncoder : UTF8Encoding { public MyEncoder() { } public override byte[] GetBytes(string s) { s = s.Replace("\\", "/"); return base.GetBytes(s); } } System.IO.Compression.ZipFile.CreateFromDirectory("C:/ABC", "C:/tmp/ABC.zip",

System.IO.Compression.ZipFile .NET 4.5 output zip in not suitable for Linux/Mac/Java

让人想犯罪 __ 提交于 2020-03-17 08:15:06
问题 While using .NET System.IO.Compression.ZipFile.CreateFromDirectory class the outcome zip is badly extracted on system with forward-slash directory separator. Reason: The zip contains backslash inside the names 回答1: To overcome this problem a workaround exists: class MyEncoder : UTF8Encoding { public MyEncoder() { } public override byte[] GetBytes(string s) { s = s.Replace("\\", "/"); return base.GetBytes(s); } } System.IO.Compression.ZipFile.CreateFromDirectory("C:/ABC", "C:/tmp/ABC.zip",

How to zip a folder in python with password?

[亡魂溺海] 提交于 2020-03-04 21:34:32
问题 With pyminizip i am able to zip a file with password in python : filepath=r"C:\Users\xxx\Desktop\myFolder\file.txt" import pyminizip pyminizip.compress(filepath, None,"output.zip", "password", 0) But how do I zip the whole folder 'myFolder' into a zip file with password? I tried removing the filename from the path but it gives the error OSError: error in opening C:\Users\xxx\Desktop\myFolder for reading EDIT : The below link has a function which will zip the directory. But It wont add a

Is there a way to add a folder to existing 7za archive?

别来无恙 提交于 2020-02-04 03:50:20
问题 I have tried adding a new folder to an existing 7za archive using the following command from command prompt: 7za.exe a repo.zip \res\pub\newfolder newfolder The above command added a folder to root of repo.zip. My intention was to add the new folder to location: \res\pub\folder inside repo.zip Can anyone suggest or give me a correct command to add folder to a specific path of an archive? Thanks, Pradeep 回答1: Try to create a source location folder which you use for an update of your

Is there a way to add a folder to existing 7za archive?

旧街凉风 提交于 2020-02-04 03:49:06
问题 I have tried adding a new folder to an existing 7za archive using the following command from command prompt: 7za.exe a repo.zip \res\pub\newfolder newfolder The above command added a folder to root of repo.zip. My intention was to add the new folder to location: \res\pub\folder inside repo.zip Can anyone suggest or give me a correct command to add folder to a specific path of an archive? Thanks, Pradeep 回答1: Try to create a source location folder which you use for an update of your

How to compress folders using zipfile python

我的未来我决定 提交于 2020-01-30 08:18:48
问题 So my program so far is successfully able to add and compress files which are present in the same directory as test.py but there is also a folder named location in the same directory which contains additional files say citynames.txt What happens is when i do a simple zip.write (The logic used in else block) location is added to the zip file however its empty that is it does not contain citynames.txt inside it for some reason please help me add the folder itself somehow ? import os import

How to compress folders using zipfile python

╄→гoц情女王★ 提交于 2020-01-30 08:18:27
问题 So my program so far is successfully able to add and compress files which are present in the same directory as test.py but there is also a folder named location in the same directory which contains additional files say citynames.txt What happens is when i do a simple zip.write (The logic used in else block) location is added to the zip file however its empty that is it does not contain citynames.txt inside it for some reason please help me add the folder itself somehow ? import os import