#Cerca i file relativi alle immagini delle lettere DATINI a partire da CSV e le copia in una nuova directory #%% import csv import os import os.path import shutil folder = "/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images" files = os.listdir(folder) for item in files: if item != ".DS_Store": src =f"{folder}/{item}" # foldername/filename, if .py file is outside folder newfolder = item.replace("_01.jpg","").replace("_02.jpg","").replace("_03.jpg","").replace("_04.jpg","").replace("_05.jpg","").replace("_06.jpg","").replace("_07.jpg","").replace("_08.jpg","").replace("_09.jpg","") try: os.makedirs(f"/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images/{newfolder}/", exist_ok=True) print('file ' + item + " c'รจ nella cartella") print('sottocartella ' + newfolder + " creata") except FileExistsError: pass dst =f"/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images/{newfolder}/" shutil.move(src, dst)