associate_directory.py 1.1 KB

1234567891011121314151617181920212223
  1. #Cerca i file relativi alle immagini delle lettere DATINI a partire da CSV e le copia in una nuova directory
  2. #%%
  3. import csv
  4. import os
  5. import os.path
  6. import shutil
  7. folder = "/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images"
  8. files = os.listdir(folder)
  9. for item in files:
  10. if item != ".DS_Store":
  11. src =f"{folder}/{item}" # foldername/filename, if .py file is outside folder
  12. 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","")
  13. try:
  14. os.makedirs(f"/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images/{newfolder}/", exist_ok=True)
  15. print('file ' + item + " c'è nella cartella")
  16. print('sottocartella ' + newfolder + " creata")
  17. except FileExistsError:
  18. pass
  19. dst =f"/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/images/{newfolder}/"
  20. shutil.move(src, dst)