since I'm fairly new to coding and python I can't solve a problem. I would like to create a code that would get exif info from .jpeg files and then create folders depending on the dates i found in exif and then move those pictures in their respective folders. Until now my code gets the dates and then creates folders(year then inside month then inside days). But i can't figure out how to move the pictures to their corresponding folders. This is my code. Any help would be appreciated.
import os
import sys
import PIL.Image
import PIL
from PIL import ExifTags
import datetime
from datetime import datetime
import os.path, time
from os import walk
import pathlib
import re
path=os.path.join(sys.argv[1])
destination=os.path.join(sys.argv[2])
#Pour creer la liste contenant les fichiers du dossier
def getListOfFiles(path):
listOfFile=os.listdir(path)
allFiles=[]
for i in listOfFile:
fullPath=os.path.join(path, i)
if os.path.isdir(fullPath):
allFiles= allFiles+getListOfFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
#print(getListOfFiles(path))
#print(len(getListOfFiles(path)))
#get metadata
foldertobemade=[]
extensions = ('.jpg')
for i in getListOfFiles(path):
#print(i) #prints all the names of images
ext = os.path.splitext(i)[-1].lower()
#print(ext)
if ext == extensions:
#print(i)
img=PIL.Image.open(i)
#print(img) #prints the image opened
exif=img._getexif()
#print(exif) #prints metadata
try:
if 36867 in exif:
#print(exif[36867])
foldertobemade.append(exif[36867])
except Exception as e:
pass
#print(foldertobemade)
for dates in foldertobemade:
#print(dates[:4])
#print(dates[5:7])
#print(dates[8:10])
for i in getListOfFiles(path):
if not os.path.exists(dates[:4]):
os.makedirs(dates[:4])
if not os.path.exists(dates[:4]+ "/" + dates[5:7]):
os.makedirs(dates[:4]+ "/" + dates[5:7])
if not os.path.exists(dates[:4]+ "/" + dates[5:7]+ "/" +dates[8:10]):
os.makedirs(dates[:4]+ "/" + dates[5:7]+ "/" +dates[8:10])