#!/usr/local/bin/perl -w
#       movephotos.pl DIR NEWDIR Firstnumber Lastnumber Addnumber
#
#
$source= $ARGV[0];
$dest = $ARGV[1];
$first = $ARGV[2];
$last = $ARGV[3];
$extra = $ARGV[4];

opendir(ORG,$source) || die("\nSorry Could not open ",$source," \n");

while( $name=readdir(ORG))      {
        $new=$name;
        next if( $name eq '.' || $name eq '..' );
	next unless($new =~ m%^(.*[^\d])(\d*)(\.[^\.]*)$%);
	$test =$2;
	$new = $1;
	$ending = $3;
	next unless $test;
	next if( $test < $first);
	next if( $test > $last);
	$newtest = $test + $extra;
	$i1 = length($test);
	$i2 = length($newtest);
        for($i=$i2; $i<$i1;$i++)	{
	$newtest = '0'.$newtest; }
	$new = $new.$newtest.$ending ;
        next unless $new;
        $com= "mv " .$source .'/'. $name . " ". $dest .'/'.$new;
        system("$com");
}
