#-*- coding:utf-8-*-
import os
import zipfile
#需求说明
#1.获取文件路径
#2.删除指定的文件夹
#3.对项目文件压缩
import shutil
import re
#删除文件夹
def deletefile(filePath):
if os.path.exists(filePath+'\\build'):
shutil.rmtree(filePath + '\\build')
shutil.rmtree(filePath + '\\app/build')
else:
print("False")
#压缩文件夹
def startdir(startdir):
#截取文件名 匹配 / -> [^/]+$
# 匹配 \ ->[^\\]+$
reg = re.findall(r"[^\\]+$",startdir)
z = zipfile.ZipFile(reg.pop(0)+'.zip', 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(startdir):
for filename in filenames:
z.write(os.path.join(dirpath, filename))
z.close()
print("压缩完成")
if __name__ == '__main__':
filePath = input("filePath:")
print(filePath)
deletefile(filePath)
startdir(filePath)