我想删除多个文件,这些文件与长列表中的项目相匹配.
['photo-1777.jpg', 'photo-4277.jpg', 'photo-620.jpg', 'photo-1078.jpg']
我try 了以下代码,但无法删除文件.
import os
path = "D://photo"
list1=['photo-1777.jpg', 'photo-4277.jpg', 'photo-620.jpg', 'photo-1078.jpg']
for x in list1:
if os.path.exists(x):
os.remove(x)