I am copying a list of images from one folder to the other. The list contains some image names that is not in the source folder. I have to copy only those image names that are both in the list and the source folder and ignore the missing names.
import shutil
import os
dst = r"C:/user/data1/"
with open('test.txt') as my_file:
for filename in my_file if os.path.exists(filename):
file_name = filename.strip()
src = r'C:/user/data2/'+ file_name
shutil.copy(src, dst + file_name)