Skip to content

Instantly share code, notes, and snippets.

@manoj382
Forked from simofacc/rename.py
Created March 11, 2018 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj382/a412803951e51cc1aae0e249c9ea0933 to your computer and use it in GitHub Desktop.
Save manoj382/a412803951e51cc1aae0e249c9ea0933 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