#!/usr/bin/perl -sw- # mengwong 20040515 # @ARGV = (http://mengwong.com/photography/3394/img0106.html, ...) # output: # 20040515-13:26:44 mengwong@newbabe:~/html/mason/www.mengwong.com/photography/thumbs% ll # total 8 # drwxrwxr-x 2 mengwong mengwong 4096 May 15 13:21 ./ # drwxr-xr-x 136 mengwong mengwong 4096 May 15 13:21 ../ # lrwxrwxrwx 1 mengwong mengwong 14 May 15 13:21 20040508-wms-wmk-wyc -> dsc_6906-s.jpg # lrwxrwxrwx 1 mengwong mengwong 8 May 15 13:20 20040509-birthday -> 42-s.jpg # lrwxrwxrwx 1 mengwong mengwong 14 May 15 13:19 20040509-dempsey -> dsc_7053-s.jpg # lrwxrwxrwx 1 mengwong mengwong 14 May 15 13:19 20040509-pool -> dsc_7244-s.jpg # lrwxrwxrwx 1 mengwong mengwong 14 May 15 12:25 20040510-merngfamily -> dsc_7940-s.jpg # lrwxrwxrwx 1 mengwong mengwong 25 May 15 12:26 little-india -> little-india-wall-1-s.JPG # 20040515-13:26:45 mengwong@newbabe:~/html/mason/www.mengwong.com/photography/thumbs% use vars qw($f $thumbdir); $thumbdir ||= "$ENV{HOME}/html/mason/www.mengwong.com/photography/thumbs"; chdir($thumbdir) or die "thumbs: unable to chdir $thumbdir"; foreach (@ARGV) { my ($file, $dir) = reverse split /\//, $_; $file =~ s/\.html//; # find the -s my ($small) = map { s/.*\///; $_ } grep { -e $_} map { "../$dir/$file-s.$_" } qw(jpg JPG); if (not $small) { warn "thumb: unable to find $dir/$file-s.jpg\n"; next; } if (-e $dir) { warn "thumb: $dir exists, and is not a symlink. skipping.\n"; next; } if (-l $dir) { if (not defined $f) { warn "thumb: $dir already exists. to overwrite, run with -f\n"; next; } else { unlink ($dir) || warn "unable to delete $dir: $!"; } } symlink ($small, $dir) || warn "unable to ln -s $small $dir: $!"; print "$dir -> $small\n"; }