#!/bin/csh -f # # Link yyyy.mm.dd-hh.mm.ss.ext -named files into source # subdirectories for my website photo galleries by date. # (ExifRenamer renames digicam .jpg, .avi, and .mov files based on EXIF timestamps.) # (tsname renames .jpg files based on the timestamp for Linux.) # # Much of this code is taken from the exif-refiler script. # # Brent Chivers 2007/Nov/25 ##! /bin/csh -fb # for setuid/setgid scripts (tsk) # set verbose # see commands before variable substitution # set echo # see commands after variable substitution unset histchars # get other users' history characters out of the way unalias * # get other users' .cshrc stuff out of the way ## set nonomatch # don't require wildcard matches # $0:t construction doesn't work! set cmd_name = $0 set cmd_name = $cmd_name:t # the name of this command set galleries = "/home/bchivers/webpages/photos/" # location of web source galleries if ($#argv == 0) then # no arguments provided echo "usage: $cmd_name [move-to_directory] exif-renamed_image_file(s)" exit endif if (-d $galleries/$1) then # first argument is a target directory set dirpath = "$galleries/$1" shift else # first argument is not a directory; move images default directories set dirpath = "/home/bchivers/webpages/photos/bdchivers" # default source gallery endif foreach file ( $* ) # process each file set name = $file:t set parts = `echo $name | /usr/bin/tr "._-" " "` if ($#parts < 4) then echo "Cannot determine path to re-file $file." else if (! -d "$dirpath/$parts[1]/$parts[2]/$parts[3]") then if (! -d "$dirpath/$parts[1]/$parts[2]") then if (! -d "$dirpath/$parts[1]") then echo "making $dirpath/$parts[1] directory." /bin/mkdir "$dirpath/$parts[1]" endif echo "making $dirpath/$parts[1]/$parts[2] directory." /bin/mkdir "$dirpath/$parts[1]/$parts[2]" endif echo "making $dirpath/$parts[1]/$parts[2]/$parts[3] directory." /bin/mkdir "$dirpath/$parts[1]/$parts[2]/$parts[3]" endif if (-d "$dirpath/$parts[1]/$parts[2]/$parts[3]") then if (-f "$dirpath/$parts[1]/$parts[2]/$parts[3]/$name") then echo "Name conflict with $name file already in $dirpath/$parts[1]/$parts[2]/$parts[3]/:" /bin/ls -l $file "$dirpath/$parts[1]/$parts[2]/$parts[3]/$name" else /bin/ln $file "$dirpath/$parts[1]/$parts[2]/$parts[3]" endif else echo "Cannot link $file -- no $parts[1]/$parts[2]/$parts[3] directory." endif endif end