import os
path = "D:\学习工作资料\授课资料\代码"
def deleteAll(path,endStr):
listDir = os.listdir(path)
for file in listDir:
if os.path.isdir(path + "\\" + file):
deleteAll(path + "\\" + file,endStr) # 递归函数
else:
if file.endswith(endStr):
os.remove(path + "\\" + file)
deleteAll(path,".py")