python3实现删除当前/指定路径下的文件/图片
删除文件夹下所有图片
file_name = "D:\\screenshot-snrks-png\\png-snrks"
for root, dirs, files in os.walk(file_name):
for name in files:
if name.endswith(".png"): # 填写规则
os.remove(os.path.join(root, name))
print("Delete File: " + os.path.join(root, name))
删除指定图片
file_name = "D:\\screenshot-snrks-png\\png-snrks\\2020-05-26-14-09-21.png"
if os.path.exists(file_name):
os.remove(file_name)
print('成功删除文件:', file_name)
else:
print('未找到此文件:', file_name)