Skip to content

Instantly share code, notes, and snippets.

@simofacc
Created March 13, 2016 00:49
Show Gist options
  • Save simofacc/f47774dff4817e775461 to your computer and use it in GitHub Desktop.
Save simofacc/f47774dff4817e775461 to your computer and use it in GitHub Desktop.
Python, rename files using csv file map
import os
import csv
with open('old-names-new-names.csv', 'rb') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in csvreader:
name = row[0] + '.jpg'
new = row[1] + '.jpg'
if os.path.exists(name):
os.rename(name, new)
else:
print name + " does not exist"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment