I want to delete multiple files which match in the items of a long list. The item in the list is like below and the list is very long:
['photo-1777.jpg', 'photo-4277.jpg', 'photo-620.jpg', 'photo-1078.jpg']
I try the following code but it fails to delete the files.
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)