#Cerca i file relativi alle immagini delle lettere DATINI e le copia #%% import csv from fileinput import filename import os import os.path import shutil output = open('datini_association_images_filename.csv', 'w') csvwriter = csv.writer(output) params = ['sigla','segnatura','Fondo','Busta','CODICE','filename_1','filename_2', 'filename_3', 'filename_4', 'filename_5', 'filename_6'] csvwriter.writerow(params) def collate (filename): csv_filelist = open('C:\\Users\\OVI-CNR\\Desktop\\Immagini Datini\\filelist_images.csv') filelist = csv.DictReader(csv_filelist) for row in filelist: file = row['filename'] filepath = row['filepath'] if filename != "" and " ": if file.__contains__(filename): print (filename) shutil.copy(filepath, 'C:\\Users\\OVI-CNR\\Desktop\\extacted_images_new') return filename else: return "not found" #%% csv_lettere = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/Immagini_lettere_OVI_Datini/datini_associated_images.csv') reader = csv.DictReader(csv_lettere) for row in reader: line = [] sigla = row['sigla'] segnatura = row['segnatura'] fondo = row['Fondo'] busta = row['Busta'] codice = row['CODICE'] filename_1 = row['filename_1'] filename_2 = row['filename_2'] filename_3 = row['filename_3'] filename_4 = row['filename_4'] filename_5 = row['filename_5'] filename_6 = row['filename_6'] new_filename_1 = collate(filename_1) new_filename_2 = collate(filename_2) new_filename_3 = collate(filename_3) new_filename_4 = collate(filename_4) new_filename_5 = collate(filename_5) new_filename_6 = collate(filename_6) line.append(sigla) line.append(segnatura) line.append(fondo) line.append(busta) line.append(codice) line.append(new_filename_1) line.append(new_filename_2) line.append(new_filename_3) line.append(new_filename_4) line.append(new_filename_5) line.append(new_filename_6) csvwriter.writerow(line) output.close() #if filepath.__contains__(filename_5):