Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Used for renaming photos in a folder using a matching ID
- 7/7/2015
- '''
- import os, csv
- #declare new dictionary
- IDs = {}
- #build dictionary using input csv file. csv should be setup as key:value pairs
- with open('ids_master.csv','r') as inputcsv:
- idReader = csv.reader(inputcsv, delimiter = ',')
- for row in idReader:
- IDs[row[0]] = row[1]
- #path to folder with photos
- photoPath = r'O:\Projects\City of Mandeville Louisiana\Fieldwork\TIFF Photos Newly Surveyed\Resource ID TIFFs'
- #counter
- count = 0
- for photo in os.listdir(photoPath):
- head, sep, tail = photo.partition('_')
- #cmecID = photo[:5] #just first 5
- cmecID = head
- try:
- if cmecID in IDs:
- shpID = IDs[cmecID]
- newName = shpID + sep + tail
- print 'Renaming ' + newName + '...'
- print photoPath + os.sep + photo
- os.rename(photoPath + os.sep + photo, photoPath + os.sep + newName)
- count += 1
- else: print """
- NO MATCH FOR FILE {0}
- """.format(photo)
- except Exception as e:
- print """
- {0}
- """.format(e)
- print """
- {0} photo's were renamed.
- """.format(count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement