python 删除目录所有文件夹下指定文件名和格式的文件
程序员文章站
2022-06-08 10:26:38
...
'''删除特定文件名的文件'''
path = "G:\\BaiduYunDownload\\"
for maindir,subdir,file_name_list in os.walk(path):
for filename in file_name_list:
print(filename)
if filename in ["数据来源说明.png","下载必看.txt","更多精品教程.url","本教程由我爱学it提供.url","百度云SVIP长期免费使用.url","高清电子书籍.url"]:
os.remove(maindir+"\\"+filename)
print("ok")
else:
print("0")
删除txt文件:
'''删除.txt文件'''
path = "G:\\BaiduYunDownload\\"
for maindir,subdir,file_name_list in os.walk(path):
for filename in file_name_list:
if(filename.endswith(".txt")):
os.remove(maindir+"\\"+filename)
else:
print("None")
上一篇: Qt获取子目录名和文件名