Software\’s whipping boy

March 9, 2013

Fixing Photo Mistakes

Filed under: Uncategorized — rslomkow @ 9:26 pm

So I messed up and deleted a bunch of photos off my Camera’s memory card by not paying attention to it.  With Linux there is a way to recover.

First you need the “testdisk” package to get you “photorec”

# sudo apt-get install testdisk

# sudo photorec /d /MYPATH /dev/MYDEVICE1

then I put together a quick python script to list out which files were recent of the 900 I had not backed up (this is just a one-off for my use case.  I just wanted the new photos from the 4th through the 9th of March 2013

#!/usr/bin/python

import os
import EXIF
import re

def matchDate(string):
  return re.match('2013:03:0[4-9]',str(string))

def dateFromFile(filename):
  fh = open(filename,'rb')
  tags = EXIF.process_file(fh)
  fh.close()
  try:
    return tags['EXIF DateTimeOriginal']
  except:
    return None

def matchFiles(files):
  for f in files:
    date = dateFromFile(f)
    if matchDate(date) != None:
      print f

filnames = os.listdir('.')
matchFiles(filnames)
Advertisements

Create a free website or blog at WordPress.com.