如何使用Python压缩目录(使用zipfile) [英] How to Zip a Directory with Python (using zipfile)

查看:99
本文介绍了如何使用Python压缩目录(使用zipfile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,我正在尝试压缩包含多个级别的文件和文件夹的目录。我可以使用walk函数命名我目录中的每个文件,我可以使用zipfile在一个文件夹中压缩一定数量的文件,但我有一段时间试图压缩整个目录。我想将它全部压缩到名为help.zip的文件中,我希望它保留原始文件结构。


在我的几次尝试中,这是最新的:

I''m relatively new to python, and am trying to zip a directory containing several levels of files and folders. I can use the walk function to name each file in my directory, and I can use zipfile to zip a flat number of files in one folder, but I am having heck of a time trying to zip the whole directory. I want to zip it all to a file called "help.zip", and I want it to retain the original file structure.

Of my several tries, here is the latest:

展开 | 选择 | Wrap | 行号

推荐答案

这是另一个可能相关的线程: http://bytes.com/forum/thread845051.html
Here''s another thread that may be relevant: http://bytes.com/forum/thread845051.html


这里''我用来备份目录内容及其子目录的脚本。可以轻松调整它以仅备份目录内容或具有特定扩展名的文件。文件路径保存在存档中。
Here''s a script that I use to backup the contents of a directory and it''s subdirectories. It can easily be adjusted to backup only the directory contents or files with specific extensions. The file path is saved in the archive.
展开 | 选择 | Wrap | 行号



Here'另一个可能相关的主题是: http://bytes.com/forum/thread845051.html



谢谢!我很感激帮助!


Thanks! I appreciate the help!


这篇关于如何使用Python压缩目录(使用zipfile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆