如何创建一个目录的zip档案并将zip文件保存在同一目录中



hi我想创建一个目录的zip档案,并将zip文件保存在同一目录中

我尝试使用shuttle库中的make_archive

但是zip文件转到错误的路径

这是我的代码:

分枝杆菌图片

def makearchive():
make_archive(
'zipfile_name', 
'zip',           # the archive format - or tar, bztar, gztar 
root_dir=None,   # root for archive - current working dir if None
base_dir=None)   # start archiving from here - cwd if None too
def downloadProject(user,projectName):
projectPath = os.path.join(BASE_DIR/'UsersProjects'/user,projectName)
buildPath = os.path.join(projectPath,'build.zip')
if os.path.isfile(buildPath):
os.remove(buildPath)
# shutil.make_archive('build', 'zip', projectPath)
makearchive(projectPath)
else:
# shutil.make_archive('build', 'zip', projectPath)
makearchive(projectPath)

我能做什么?

根据我所看到的,您没有使用projectPath变量,因为您的makearchive函数没有接收到任何参数,我给您留下一个如何执行的代码示例

def makearchive(projectpath=None):
make_archive(
'zipfile_name', 
'zip',           # the archive format - or tar, bztar, gztar 
root_dir=projectPath,   # root for archive - current working dir if None
base_dir=None)   # start archiving from here - cwd if None too

最新更新