winzip¶
A data/file compress utility module. You can easily programmatically add files and directorys to zip archives. And compress arbitrary binary content.
zip_a_folder()
: add folder to archive.zip_everything_in_a_folder()
: add everything in a folder to archive.zip_many_files()
: Add many files to a zip archive.write_gzip()
: Write binary content to gzip file.read_gzip()
: Read binary content from gzip file.
中文文档
提供了若干个文件和数据压缩的快捷函数。
zip_a_folder()
: 将目录添加到压缩包。zip_everything_in_a_folder()
: 将目录内的所有文件添加到压缩包。zip_many_files()
: 将多个文件添加到压缩包。write_gzip()
: 将二进制数据写入文件, 例如python pickle, bytes string。read_gzip()
: 读取解压后的二进制数据内容。
注: python中zipfile包自带的ZipFile方法的用法如下:
基本用法:
with ZipFile("filename.zip", "w") as f:
f.write(path)
其中path是文件路径。 如果path是文件夹, 并不会将文件夹内所有的文件添加到压缩包中。
相对路径压缩:
比如你有一个路径 C:\download
eadme.txt
, 如果当前路径是 C:\
,
而此时你将 readme.txt
添加到压缩包时则是在压缩包内添加一个: download
eadme.txt
,
如果当前路径是 C:\download\
, 则在压缩包内添加的路径则是: readme.txt
-
filetool.winzip.
zip_a_folder
(src, dst)[source]¶ Add a folder and everything inside to zip archive.
Example:
|---paper |--- algorithm.pdf |--- images |--- 1.jpg zip_a_folder("paper", "paper.zip") paper.zip |---paper |--- algorithm.pdf |--- images |--- 1.jpg
中文文档
将整个文件夹添加到压缩包, 包括根目录本身。
-
filetool.winzip.
zip_everything_in_a_folder
(src, dst)[source]¶ Add everything in a folder except the root folder it self to zip archive.
Example:
|---paper |--- algorithm.pdf |--- images |--- 1.jpg zip_everything_in_folder("paper", "paper.zip") paper.zip |--- algorithm.pdf |--- images |--- 1.jpg
中文文档
将目录内部的所有文件添加到压缩包, 不包括根目录本身。