summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog7
-rw-r--r--README9
-rwxr-xr-xrenrot75
3 files changed, 77 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 651959c..15973d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
$Log$
+Revision 1.57 2006/05/03 21:59:52 zeus
+file aggregation via option --aggr-template has been implemented.
+control code for file name originality has been moved from template2name() to main().
+README edited
+
Revision 1.56 2006/05/02 19:08:59 zeus
item about aggregation is added to TODO.
-minor language ixes in README
+minor language ixes in README.
Revision 1.55 2006/05/02 09:07:02 andy
Wrote RESTRICTIONS section in README.
diff --git a/README b/README
index ec94c27..16a317a 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ of project is short form of 'REName and ROTate' and no other interpretation
will be used.
Renrot is intended to work only in current directory with all files of the
-extension, specified after --ext. You can change the behaviour by specify
+extension, specified after --ext. You can change the behaviour by specifying
--work-directory option.
New template ideology was implemented. It includes flexibility in file name
@@ -28,6 +28,8 @@ Furthermore, the script can put a comment to:
Personal data could be specified via XMP tags defined in configuration file.
+In addition renrot can aggregate all files in directories according the given
+date/time pattern template, set with --aggr-template.
WHY RenRot?
@@ -41,6 +43,7 @@ namely RenRot? Because:
libjpeg6 (the best open tool to operate JPEG format files, to correctly
rotate both, the very file and the thumbnail inside it);
- it has very much flex file naming template engine;
+ - it has very much flex file aggregation template engine;
- it works in batch mode.
@@ -61,6 +64,10 @@ applications of the script:
rename each file according to the given template
renrot --name-template="01.%c.%Y%m%d%H%M%S.%i.%E%F%W%I" --ext JPG
+ rename each file according to the given template and files aggregation
+ according the date
+ renrot --name-template="%y%m%d%H%M%S.%i" --aggr-template "%Y%m%d" --ext JPG
+
rotate each file and their thumbnail by 90CW in specified directory
renrot --rotate 90 --ext '*.jpg' --work-directory="/tmp/images"
diff --git a/renrot b/renrot
index 5aa5a64..3fa6e61 100755
--- a/renrot
+++ b/renrot
@@ -19,6 +19,7 @@ my $rotateThumbnail; # define the angle, to rotate on, 90 or 270
my $noRename; # no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg
my $noComment; # no comment needed
my $nameTemplate; # template for the filename taken from CLI
+my $aggrTemplate; # template for the files aggregation taken from CLI
my $extentionToProcess; # the extention of files to work with
my $extentionToProcessLowCase; # lowercased extention of files to work with
my $usageOutput = 0; # flag to show the usage
@@ -71,6 +72,7 @@ sub getopt {
"no-rename" => \$noRename,
"comment-file=s" => \$comfile,
"name-template=s" => \$nameTemplate,
+ "aggr-template=s" => \$aggrTemplate,
"mtime" => \$mtime,
"config-file|c=s" => \$configFile,
"v+" => \$verbose,
@@ -247,15 +249,23 @@ foreach $file ( @files ) {
#
if ( defined $noRename ) {
infomsg ("No renaming asked, filename is left untouched.\n");
- $newfilename = $file;
+ if ( ($newfilename) = ( $file =~ /^(.*)\.jpg/ ) ) {
+ $filenameshash{$newfilename} = 1;
+ }
}
else {
- $newfilename = sprintf("%s.%s", template2name($NameTemplate), $extentionToProcessLowCase);
+ $newfilename = template2name($NameTemplate);
+ if ( $filenameshash{$newfilename} ) {
+ $newfilename = sprintf("%s.%.4d",$newfilename,$filecounter);
+ }
+ $filenameshash{$newfilename} = 1;
+
+ $newfilename = sprintf("%s.%s", $newfilename, $extentionToProcessLowCase);
if ( $file ne $newfilename ) {
if ( -f $newfilename ) {
- fatalmsg ("File $newfilename already exists!\n"), die
- };
+ fatalmsg ("File $newfilename already exists!\n"), die;
+ }
rename ( $file, $newfilename )
|| ( fatalmsg ("Unable to rename $file -> $newfilename.\n"), die );
print "Renamed: $file -> $newfilename\n";
@@ -342,6 +352,27 @@ foreach $file ( @files ) {
closedir(DIR);
+########################################################################################
+#
+# file aggregation if requested
+#
+if ( defined $aggrTemplate ) {
+ infomsg ("NOW IS FILE AGGREGATION\n=======================\n\n");
+ $filecounter=1;
+ foreach $file ( sort ( keys %filenameshash ) ) {
+ $file .= ".jpg";
+ $info = $exifTool->ImageInfo($file);
+ $newfilename = template2name($aggrTemplate);
+ if ( not -d $newfilename ) {
+ unless ( mkdir $newfilename ) { errmsg ("$newfilename wasn't created!\n"); }
+ }
+ infomsg ( "$file has been aggregated to the directory $newfilename\n" );
+ $newfilename .= "/" . $file;
+ rename ( $file, $newfilename ) || ( fatalmsg ("$file -> $newfilename\n"), die );
+ $filecounter++;
+ }
+}
+
exit 0;
########################################################################################
@@ -404,7 +435,7 @@ sub getTimestamp {
$timestamp = timeNow();
warnmsg ("EXIF timestamp isn't correct, using timeNow()!\n");
}
-
+
return $timestamp;
}
@@ -553,6 +584,7 @@ infomsg (
it's for the files which were rotated, but thumbnail wasn't
--no-rename no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg
--name-template <TPL> filename template (see manual for details)
+ --aggr-template <TPL> aggregation template (see manual for details)
--mtime to set file mtime according DateTimeOriginal tag value
--comment-file <FILE> file with commentary
--version the version of this script
@@ -637,12 +669,6 @@ sub template2name {
else { $thename .= $substrchar; }
}
- if ( $filenameshash{$thename} ) {
- $thename = sprintf("%s.%s",$thename,$templatehash{"c"});
- }
-
- $filenameshash{$thename} = 1;
-
return $thename;
}
@@ -659,7 +685,7 @@ renrot [OPTIONS]
=head1 DESCRIPTION
B<RenRot> is intended to work ONLY in current directory. You can change the
-behaviour by specify B<--work-directory> option.
+behaviour by specifying B<--work-directory> option.
Renrot renames files according the DateTimeOriginal and FileModifyDate EXIF
tags, if they exist. Otherwise, the name will be set according to the current
@@ -684,6 +710,9 @@ The script can also put commentary into:
Personal details can be specified via XMP tags defined in a configuration
file, look L<CONFIG> section.
+In addition renrot can aggregate all files in directories according the given
+date/time pattern template, set with B<--aggr-template>.
+
=head1 OPTIONS
=over
@@ -780,6 +809,28 @@ B<%y> last two digits of year (00..99)
=back
+=item B<--aggr-template> I<Aggregation TEMPLATE>
+
+template, which is used for file aggregation. Aggragation fulfils according date/time patterns.
+
+=over
+
+B<%d> day of the month (01-31)
+
+B<%H> hour (00-23)
+
+B<%M> minute (00-59)
+
+B<%m> month (01-12)
+
+B<%S> second (00-59)
+
+B<%Y> year (1900, 1901, and so on)
+
+B<%y> last two digits of year (00..99)
+
+=back
+
=back
=head1 B<EXAMPLES>

Return to:

Send suggestions and report system problems to the System administrator.