Skip to content

Instantly share code, notes, and snippets.

@Achifaifa
Created July 10, 2014 17:06
Show Gist options
  • Save Achifaifa/f3644fb2de9dda14e3a8 to your computer and use it in GitHub Desktop.
Save Achifaifa/f3644fb2de9dda14e3a8 to your computer and use it in GitHub Desktop.
Small script for product photography sessions with hundreds of files. Take photo, note the number (DSC_XXXX.nef), and add the product name and the weight (Requirements for this particular assignment). run [python this_file.py reference_file], and all the photos will be renamed to product_(weight kg).nef. Fiddling a lite with the code allows to w…
#! /usr/bin/env python
import os, sys
if __name__=="__main__":
try: os.chdir(os.path.dirname(__file__))
except OSError: pass
filepath="./"+sys.argv[1]
with open (filepath,"r") as listfile:
for line in listfile:
for filename in os.listdir("./"):
if filename=="DSC_"+line.partition(',')[0]+".nef":
targetname=line.partition(',')[2].partition(',')[0]+"_("+line.strip().partition(',')[2].partition(',')[2]+"kg).nef"
print filename,targetname
os.rename(filename,targetname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment