-
-
Save manoj382/a412803951e51cc1aae0e249c9ea0933 to your computer and use it in GitHub Desktop.
Python, rename files using csv file map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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