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 new folder but I've yet to figure out how to move the files based on it's filename, For example below I want to move the images accordingly.
- 1600_01.jpg ---> folder 1
- 1700_01.jpg ---> folder 1
- 1800_02.jpg ---> folder 2
- 1900_02.jpg ---> folder 2
- 2000_03.jpg ---> folder 3
- 2100_03.jpg ---> folder 3
This is my code thus far for moving entire files in a folder to a destination that I want.
# Moving Files from one place to another
import shutil
import os
sourcefile = 'Desktop/00/'
destination = 'Desktop/00/d'
# Loading the files from source
files = os.listdir(path=sourcefile)
# Reading the files in folder
for f in files:
shutil.move(sourcefile+f, destination)