#!perl
use warnings;
use strict;
use File::Copy;
# Functions are defined at the bottom of this script.
# configurable variables go here:
my $new_folder = 'C:\new_folder';
# end of configurable variables
# get the date stamp like "2014-11-26-1315h"
my $date_stamp = get_date_stamp();
# glob only works if this script is in the same folder as the original jpeg images
my @old_files = glob '*.jpg';
# copy the files and include the date stamp in the new file name.
# we're using keys because the key is used to get the file's number.
# we're trying to build names like "2014-11-26-1315h 5.jpg".
# can't remember how to force it use 3 digits for a number so it would be 005. fix later.
foreach my $key (keys @old_files) {
copy($old_files[$key], "$new_folder\\$date_stamp $key.jpg")
or die "could not copy $old_files[$key]";
}
######################################
# Functions:
#
#
###############################################################
# Function "get_date_stamp" returns the date stamp
# function localtime() converts the time() into a 9 segment array:
# 0 1 2 3 4 5 6 7 8
# ($sec,$min,$hour,$day,$mon,$year19,$wday,$yday,$isdst) = $localtime(time);
# $month number starts at 0 instead of 1, so add 1 before using it
# $year19 counts from 1900, so add 1900 before using it
sub get_date_stamp {
my ($_sec,$_min,$_hour,$_day,$_mon,$_year19,$_wday,$_yday,$_isdst) = localtime(time); #assign all of the variables
++$_mon; #make the month 1 larger because it starts from 0
#use 4 digit year, 2 digit month, 2 digit day, 2 digit hour, 2 digit minutes
my $_date_stamp = sprintf ("%04d-%02d-%02d-%02d%02dh", $_year19+1900, $_mon, $_day, $_hour, $_min); #displays like "2014-07-14-1315h"
return $_date_stamp;
} #/sub get_date_stamp
###############################################################