py目錄下獲取指定字尾檔案打包成zip檔案

loooosss發表於2018-12-05
file_dir = os.path.abspath(`.`) + "/MarkCoin"

def zip_ya():
L = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == `.png` or os.path.splitext(file)[1] == `.xlsx`:
L.append(file)

z = zipfile.ZipFile(file_dir11 + `aa_file.zip`, `w`)
for i in range(len(L)):
z.write(file_dir11+L[i])
z.close()

if __name__ == `__main__`:
  zip_ya()

相關文章