I have a folder with 10 images that I wish to move into a new folder based on it\'s current filenames. I\'ve successfully been able to move every images in the folder into a
You can just try to use os.path.exists() to check if the folder exists, if it exists copy the jpg into it. By the way it's better if you use copy, because when you use move you are basically mixing everything up if you do something wrong.
import os, shutil
os.chdir("<abs path to desktop>")
for f in os.listdir("folder"):
folderName = f[-6:-4]
if not os.path.exists(folderName):
os.mkdir(folderName)
shutil.copy(os.path.join('folder', f), folderName)
else:
shutil.copy(os.path.join('folder', f), folderName)