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.
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)
At this point all you need is to modify destination based on the last digit:
for f in files:
folder_number = f.split('.')[0][-1]
shutil.move(sourcefile+f, destination + '/' + folder_number + '/' + f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With