我正在尝试写入包含现有文件夹的zip存档。
到目前为止,我只能得到:
x.write(newfiles)
给了我dir1/dir2/dir...n/newfiles
或 >
x.write(newfiles, os.path.rel(newfiles, root))
它在我的档案库中提供了我在所有子目录之外的所有新文件。
但是,我需要完成的是将我的新文件写入我的子目录中已存在的档案。
请帮忙!谢谢!
我的代码:
#create a list of the png files to be added
img_lib = []
for root, dirs, files in os.walk(img_dir):
for i in files:
img_lib.append(root + '/' + i)
#open kmz archive for editing in 'append' mode
kmzarc = zipfile.ZipFile(TCP_kmz, mode = 'a')
#loop through list of available png files in img_lib and add to archive
for i in img_lib:
kmzarc.write(i, 'images/'+os.path.relpath(i, root))
#close file
kmzarc.close()