Created
March 13, 2016 00:49
-
-
Save simofacc/f47774dff4817e775461 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