python pyz7r 压缩后解压时出现“不支持的功能”

问题描述 投票:0回答:1

我正在尝试使用

pyz7r
Python模块来压缩我拥有的一些文件夹,我想要的是确保这些文件夹被压缩到存档中,如下所示:

Here are my folders.

SomeFolder.
  - File1.txt
  - File2.txt
AnotherOne
  - Wow.txt
  - IAmAFile.txt

I want the output after creating the 7z file and unzip it to be as the following:

UnzippedFolder
  SomeFolder.
    - File1.txt
    - File2.txt
  AnotherOne
    - Wow.txt
    - IAmAFile.txt

我听说过使用这个:

folders = ["./SomeFolder", "./AnotherOne"]

with py7zr.SevenZipFile("Zipped.7z", 'w') as archive:
    for folder in folders:
        print(f"Zipping {folder}....")
        archive.writeall(FOLDER)
        print("DONE!")

直到这里一切都很好,直到我尝试使用 7zip 程序解压缩文件夹时,它返回以下错误:

无法将文件打开为 [7z] 存档
不支持的功能

我不知道问题出在哪里。另外,我从未尝试过

writeall
(或从未为我工作过)功能,但据我所知,它执行的文件和文件夹顺序与我想要的相同。

如果有帮助的话,我使用的是 Windows 11。

python windows zip archive 7zip
1个回答
0
投票
import py7zr

folders = ["./SomeFolder", "./AnotherOne"]

with py7zr.SevenZipFile("Zipped.7z", 'w') as archive:
    for folder in folders:
        print(f"Zipping {folder}....")
        # Add the entire folder and its contents to the archive
        archive.writeall(folder, arcname=folder)
        print("DONE!")

# Now, when you extract the archive, it should have the desired structure.
© www.soinside.com 2019 - 2024. All rights reserved.