Python 使用shutil.make_存档压缩文件时出现意外文件

Python 使用shutil.make_存档压缩文件时出现意外文件,python,python-3.x,zip,shutil,Python,Python 3.x,Zip,Shutil,我正在尝试使用shutil.make_存档压缩文件 当我使用: import shutil shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test') make_archive( 'zipfile_name', 'zip', # the archive format - or tar, bztar, gztar root_dir=file_dir, # root for archive - curr

我正在尝试使用shutil.make_存档压缩文件

当我使用:

import shutil
shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test')
make_archive(
  'zipfile_name', 
  'zip',           # the archive format - or tar, bztar, gztar 
  root_dir=file_dir,   # root for archive - current working dir if None
  base_dir=file_dir)   # start archiving from here - cwd if None too
我在zip_文件中得到了一个zip_文件,zip_文件中的zip_文件似乎是一个损坏的文件。有人知道怎么处理吗

但是,当我使用:

import shutil
shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test')
make_archive(
  'zipfile_name', 
  'zip',           # the archive format - or tar, bztar, gztar 
  root_dir=file_dir,   # root for archive - current working dir if None
  base_dir=file_dir)   # start archiving from here - cwd if None too
除文件夹目录错误外,它使所有内容都正确无误。 例如,如果file_dir='C:\Users\aaa\Desktop\test\bbb' zip文件的结构将是:

 Users  
         aaa
              Desktop
                     test
                         bbb
我希望它能是bbb/唯一的


有什么想法吗?非常感谢您的帮助。

我认为解决方案是在不同的目录中创建zipfile。从那里开始,就像

shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test', "bbb")

应该给你一个bbb目录的存档

当然可以,但为什么它不能在特定目录中创建自己的zip文件呢?我不是100%确定,但我怀疑zipfile是作为过程的第一步创建的,然后通过遍历目标目录来填充。由于zipfile位于目标目录中,它会看到它自己的一个未完成版本,其中包括。这就解释了为什么它没有出现在另一个文件夹中。非常感谢你。