py目录下获取指定后缀文件打包成zip文

发布时间:2019-04-17 21:35:11编辑:auto阅读(2049)

    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()

关键字