python 删除多个同一后缀名文件(基于python 3.X)

import os


def remove():
filearray = []
address_Excel="E:\totally\FinancePDF"
f_list = os.listdir(address_Excel)
for fileNAME in f_list:
# os.path.splitext():分离文件名与扩展名
if os.path.splitext(fileNAME)[1] == '.xlsx':
filearray.append(fileNAME )
# 以上是从pythonscripts文件夹下读取所有excel表格,并将所有的名字存储到列表filearray
print("在默认文件夹下有%d个文档" % len(filearray))
ge = len(filearray)

for i in range(ge):
fname = filearray[i]
os.remove(fname)
print('remove successful' )
if __name__ == "__main__":
remove()
原文地址:https://www.cnblogs.com/setname/p/8417769.html