[英]zip a folder and store zipped file into another folder in python
I am zipping a folder in python like 我在python中压缩文件夹
mypath = "c:\Test\mypath"
foldername = "mydata"
zipf = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir(mypath, zipf)
zipf.close()
the output of zipped file mydata.zip is located at mypath "c:\\Test\\mypath\\mydata.zip" But i want mydata.zip file into another folder like "c:\\Test\\mypath\\anotherfolder\\mydata.zip" 压缩文件mydata.zip的输出位于mypath“ c:\\ Test \\ mypath \\ mydata.zip”,但是我希望将mydata.zip文件放入另一个文件夹,例如“ c:\\ Test \\ mypath \\ anotherfolder \\ mydata.zip”
Please help me to do achieve this. 请帮助我做到这一点。
The zip file is created in the current working directory. 该zip文件在当前工作目录中创建。 that is "c:\\Test\\mypath" To achieve my requirement, I changed the current working directory using os.chdir() as "c:\\Test\\mypath\\anotherfolder" and got the zip file in the same location
那是“ c:\\ Test \\ mypath”为了达到我的要求,我使用os.chdir()将当前工作目录更改为“ c:\\ Test \\ mypath \\ anotherfolder”,并将zip文件放在同一位置
mypath = "c:\Test\mypath"
foldername = "mydata"
anotherpath = "c:\Test\mypath\anotherfolder"
os.chdir(anotherpath)
zipf = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir(mypath, zipf)
zipf.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.