import os
import shutil
source_folder = r'C:\Users\Administrator\Desktop\test\source'
destination_folder = r'C:\Users\Administrator\Desktop\test\goal'
imgType = '.png'
os.makedirs(destination_folder, exist_ok=True)
with open('name.txt', 'r') as file:
filenames = file.readlines()
with open('isNotExit.txt', 'w') as f:
for filename in filenames:
filename = filename.strip() + imgType
source_path = os.path.join(source_folder, filename)
destination_path = os.path.join(destination_folder, filename)
if os.path.isfile(source_path):
shutil.copy2(source_path, destination_path)
else:
f.write(filename + "\n")
print(f"The file {filename} does not exist and cannot be moved.")
f.close()