find_letter_image.py 959 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #Cerca i file relativi alle immagini delle lettere DATINI e le copia
  2. #%%
  3. import csv
  4. import os
  5. import os.path
  6. import shutil
  7. import glob
  8. output = open('images_notfound.csv', 'w')
  9. csvwriter = csv.writer(output)
  10. params = ['CODICE']
  11. csvwriter.writerow(params)
  12. #%%
  13. #rootdir = os.getcwd()
  14. csv_lettere = open('C:\\Users\\OVI-CNR\\Desktop\\Immagini Datini\\estrazione_immagini_1.csv')
  15. reader = csv.DictReader(csv_lettere)
  16. for row in reader:
  17. line = []
  18. codice = row['CODICE']
  19. for subdir, dirs, files in os.walk("Z:\\IMMAGINI DATINI"):
  20. for file in files:
  21. #print os.path.join(subdir, file)
  22. filepath = subdir + os.sep + file
  23. if filepath.__contains__(codice):
  24. line.append (codice)
  25. shutil.copy(filepath, 'C:\\Users\\OVI-CNR\\Desktop\\extracted_images')
  26. else:
  27. print (codice + " not found")
  28. csvwriter.writerow(line)
  29. output.close()