使用shutil.make_archive()压缩目录,同时保留目录结构。
- 论坛
- 使用shutil.make_archive()压缩目录,同时保留目录结构。
10 浏览
使用shutil.make_archive()压缩目录,同时保留目录结构。
我正在尝试使用以下代码将名为test_dicoms
的目录压缩成名为test_dicoms.zip
的zip文件:
shutil.make_archive('/home/code/test_dicoms', 'zip', '/home/code/test_dicoms')
问题是,当我解压缩时,所有位于/test_dicoms/
中的文件都被提取到/home/code/
而不是文件夹/test_dicoms/
,而且被提取到/home/code/
。因此,/test_dicoms/
中有一个名为foo.txt
的文件,当我压缩和解压缩后,foo.txt
的路径是/home/code/foo.txt
,而不是/home/code/test_dicoms/foo.txt
。我该如何修复这个问题?另外,我正在处理的一些目录非常大。我需要在代码中添加任何内容以使其成为ZIP64,还是该函数可以自动智能地处理?
这是当前创建的存档中的内容:
[gwarner@jazz gwarner]$ unzip -l test_dicoms.zip
Archive: test_dicoms.zip
Length Date Time Name
--------- ---------- ----- ----
93324 09-17-2015 16:05 AAscout_b_000070
93332 09-17-2015 16:05 AAscout_b_000125
93332 09-17-2015 16:05 AAscout_b_000248