Version 0 of Rename and redate photo-files

Updated 2006-06-26 14:24:12

HJG 2006-05-25 Digital cameras typically produce pictures with filenames like "100_0001.jpg", "Dscn1234.jpg" or "Imgp0001.jpg".

For organizing a collection of photos, it is better to rename them to a filename based on a prefix and the date and time of when the picture was taken, such as "holidays_2005-12-13_14-15-16.jpg" or "gurt2005_1213_141516a.jpg".

Some software that can do such renaming:

  • Exifer, see www.exifer.friedemann.info (Freeware)
  • mapivi MaPiVi - Martin's Picture Viewer (Perl/Tk)

Of course, we can do that with Tcl/Tk also, here is a simple program to do just the renaming:


  # FotoRename1.tcl - HaJo Gurt - 2006-06-25

  catch {console show}
  wm withdraw .

  set fnFormat "gurt%Y_%m%d_%H%M%S"
  set dir "."

  puts "# FotoRename1:"
  foreach fname1 [lsort [glob -dir $dir "*.jpg"]] {
     file stat $fname1 stat
     array set attr [file attributes $fname1]
     set fn1 [file tail $fname1]

    if { $stat(type) == "file" } {
      set fn2 [clock format $stat(mtime) -format $fnFormat ]
      set ext ".jpg"
      append fn2 $ext
      if { [file exist $fn2] } {
        puts "# File exists: $fn2"                ;# don't overwrite existing files
      } else {
        puts [format "mv %-30s %s" $fn1 $fn2]
        file rename -- $fn1 $fn2                
      }
    }
  }

  puts "# Done."

Category File