A Python script to organize digital photos

Apr 02, '03 09:46:00AM

Contributed by: Anonymous

I tried different ways of organizing my digital photographs and eventually I came to a conclusion that the easiest one for me is to keep all my photos in one directory. To put them all in order I give each of them a filename which looks like this:

yymmdd-title-num.jpg

Example:

030224-trip-to-boston-033.jpg

I found that now I can find the right photograph in a matter of seconds even if I have thousands of them! First I download photos from my camera to my Pictures directory. Second I run the Python script shown below to rename all of them and move to my photo collection.

To make the script to work with Jaguar:
  1. Name the script; for example, 'mypics'
  2. Copy it to ~/bin directory
  3. Type chmod +x ~/bin/mypics to make it executable
  4. Modify the directories in the script
  5. Run it
#!/usr/bin/env  python

import os, sys, time

#Change these directories to your own settings
picturesDownloadDirectory="/Users/dimus/Pictures"
newPhotosDirectory="/Users/dimus/newPhotos"

#Don't change anything below this line:
#______________________________________
os.chdir(picturesDownloadDirectory)
files=os.listdir(os.curdir)
pics=[]

for i in files:
  if i [-3:].upper()=="JPG":
    pics.append(i)

print "Enter the name of the pictures: ",
name=raw_input()
print "nThere are %s pictures in your Pictures directory to move"

local_time=time.localtime(time.time())
year=str(local_time[0])[2:]
month=str(local_time[1])
if len(month)
[robg adds: I have not tested this script...]

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2003033122521887