#!/usr/bin/perl =pod NAME copy-nikon-data-from-cf copy nikon images from a compact flash card. USAGE copy-nikon-data-from-cf INPUT none OUTPUT the output from this routine is a directory structure with image data copied from a compact flash card. the data is written into $odir with a naming convention defined in the NOTES section below. VARIABLES $cf -- default is /mnt/camera/dcim. this variable identifies the location of the compact flash card on the computer. $odir -- default is ~/cf-data. name of output-data directory. @nikon_dirs -- list of nikon image directories on the compact flash card. @image_list -- list of images in a nikon image directory. $dir -- directory name; foreach loop variable. $file -- file name; foreach loop variable. $mode -- default 0755; permissions mode for directory creation. $user -- user name. $home -- user home directory. $dir_num -- nikon image directory prefix $file_pre -- nikon image file prefix $file_num -- nikon image file number $file_ext -- nikon image file extension. NOTES the naming convention used by nikon cameras to store images on a compact flash card is as follows: dcim/NNNnikon/dscnNNNN.jpg or dcim/NNNnikon/sta_NNNN.jpg <== not sure about this dcim/NNNnikon/stb_NNNN.jpg <== not sure about this ... where NNN is a 3-digit number and NNNN is a 4-digit number. the prefix "img" means this is a single image, while the prefixes "sta", "stb", ... refer to photos shot with canon's stitch mode for a multi-image panoramic. when the nikon utilities copy the images from the compact flash card to the computer hard disk, they change the file name as follows: XXXnikon/dscnYYYY.jpg ==> ImgYYYY.JPG or XXXnikon/sta_YYY.jpg ==> XXX-YYYY_STA.JPG <== don't know about this so this is what we do here with this routine. AUTHOR Written Oct 31, 2002 by Joe Werne =cut use File::Copy; use strict; # check usage name if ($#ARGV != -1 && $#ARGV != 0) { die "USAGE: copy-nikon-data-from-cf []" } # define variables my($user) = $ENV{USER}; my($home) = $ENV{HOME}; my($odir) = "$home/cf-data"; my($mode) = 0755; my(@nikon_dirs); my(@image_list); my($user); my($cf) = "/mnt/camera/dcim"; my($dir); my($dir_num); my($file); my($file_pre); my($file_num); my($file_ext); my($file_pre_uc); my($file_ext_uc); my($output_image_file); # check for optional argument if ($#ARGV == 0) { $cf = "$ARGV[0]"; print "\$cf = $cf\n"; } # create $odir if (! -d "$odir") { mkdir "$odir",$mode; } # change to digital camera image directory in $cf chdir "$cf"; # obtain a list of nikon image directories on the compact flash card @nikon_dirs = `/bin/ls -d *nikon`; chomp @nikon_dirs; # consider each nikon image directory foreach $dir (@nikon_dirs) { # create the nikon image directory in $odir. if (! -d "$odir/$dir") { mkdir "$odir/$dir",$mode; } # change into $cf/$dir chdir "$dir"; # get list of images in $dir @image_list = `/bin/ls`; chomp @image_list; # get $dir numeric prefix $dir_num = $dir; $dir_num =~ s/(\d+)nikon/$1/; # copy images in $odir/$dir, but rename image files consistent with the # manner in which nikon's utilities rename the files. foreach $file (@image_list) { # get file prefix $file_pre = $file; $file_pre =~ s/([^\d]+)\d.*/$1/; # get file number $file_num = $file; $file_num =~ s/${file_pre}(\d+)\..*/$1/; # get file extension $file_ext = $file; $file_ext =~ s/${file_pre}${file_num}\.(.*)/$1/; print "\$file_pre = $file_pre\n"; print "\$file_num = $file_num\n"; print "\$file_ext = $file_ext\n"; # construct output image file name (like the nikon utilities would) $file_pre_uc = uc $file_pre; $file_ext_uc = uc $file_ext; $output_image_file = "Img${file_num}.$file_ext_uc"; # offer some feedback to user print "$file => $odir/$dir/$output_image_file\n"; # finally, copy the file copy $file,"$odir/$dir/$output_image_file"; } # change into $cf chdir "../"; } __END__