#!/usr/local/bin/perl -w # # mkcontact.recent # # Each month I toss photos in a directory for the month. # Sometimes I pull items out for special handling, so the # monthly directories are just random photos. # # Find any such directory with files in it which are newer # than 2 days. See that there is either no index.html file # (or index.wc), or if there is that the first line of the file # is "_TITLE_". If so, force a rebuild. # # This is very particular to my setup. You may have similar # issues, and thus might use something similar to this. # # # The home for this package is at: # http://mordred.ao.com/mkcontact/ # # Dave Regan # 8 May 2000 # regan@ao.com # use strict; use Getopt::Long; use vars qw(%Args); %Args = ( 'mkcontact' => '/usr/local/bin/mkcontact', 'home' => '/home/regan/public_html/Photos', 'time' => 2, ); ### ### Main program ### my($dir, @dirs); GetOptions(\%Args, "mkcontact=s", "home=s", "time=i"); chdir($Args{'home'}) || die "Cannot go home: $!"; @dirs = sort(`find . -type d`); for $dir (@dirs) { chomp $dir; ProcessDirectory($dir); } ### ### ProcessDirectory ### ### See if there is an index file, and check file dates. ### sub ProcessDirectory { my($dir) = @_; my($file, @files, $line, $winner); # See if there is an index file to keep us from working. if (-f "$dir/index.html" || -f "$dir/index.wc") { open(WC, "<$dir/index.wc") || return; $line = ; close WC; return unless ($line =~ /_TITLE_/); } # See if there are any recent image files. opendir(DIR, $dir) || return; @files = sort(readdir(DIR)); closedir DIR; $winner = 0; for $file (@files) { next unless ($file =~ /\.(jpg|gif)$/); next if ($file =~ /\.t\./); next if (-M "$dir/$file" > $Args{'time'}); #print "Winner because of $dir/$file ", -M "$dir/$file", "\n"; $winner++; } return unless $winner; # We have a winner, make a contact sheet. print "Make a contact sheet for $dir\n"; system("$Args{'mkcontact'} --force $dir"); }