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

2020-01-20 16:45:32 浏览数 (1)

代码语言:javascript复制
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()
zip

0 人点赞