summaryrefslogtreecommitdiffabout
authorAndy Shevchenko <andy@smile.org.ua>2012-07-29 08:47:33 (GMT)
committer Andy Shevchenko <andy@smile.org.ua>2012-07-29 08:47:33 (GMT)
commit388814857c45c9076d88da6eb89c7180e9b7dbfd (patch) (side-by-side diff)
tree03f46eeda6585286e16fdfd1bc3b18d2f94f0252
parentd7282126855b13df51fab62b97f50678cbfd4d41 (diff)
downloadrenrot-388814857c45c9076d88da6eb89c7180e9b7dbfd.tar.gz
renrot-388814857c45c9076d88da6eb89c7180e9b7dbfd.tar.bz2
fileutil: introduce splitext() to get base and extension of filename
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> git-svn-id: file:///svnroot/renrot/trunk@618 fe2816f4-e837-0410-b10a-f608c9d244a1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Image/RenRot/FileUtil.pm9
-rwxr-xr-xrenrot30
2 files changed, 16 insertions, 23 deletions
diff --git a/lib/Image/RenRot/FileUtil.pm b/lib/Image/RenRot/FileUtil.pm
index 472fbf0..320aee7 100644
--- a/lib/Image/RenRot/FileUtil.pm
+++ b/lib/Image/RenRot/FileUtil.pm
@@ -15,7 +15,7 @@ use Image::RenRot::Logging;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
-@EXPORT = qw(makedir);
+@EXPORT = qw(makedir splitext);
########################################################################################
#
@@ -150,5 +150,12 @@ sub piper {
return join("", @piped_arr);
}
+sub splitext {
+ my $filename = shift;
+
+ return ($1, $2) if ($filename =~ m/(.*)\.([^\/\.]+)$/);
+ return ($filename, "");
+}
+
########################################################################################
1; # end
diff --git a/renrot b/renrot
index 8d4c599..ea0f97b 100755
--- a/renrot
+++ b/renrot
@@ -746,9 +746,6 @@ sub renameFile {
$newFileName = $file;
$filenameshash{$newFileName} = $unixTime;
} else {
- my $ext = ($file =~ m/(\.[^\.]+)$/) ? $1 : "";
- my $extLen = length($ext);
-
$newFileName = template2name (
$exifToolObj,
$infoObj,
@@ -759,11 +756,11 @@ sub renameFile {
$angleSuffix
);
- if ($filenameshash{$newFileName . $ext}) {
- $newFileName .= "." . sprintf($counterSize, $fileCounter) . $ext;
- } else {
- $newFileName .= $ext;
- }
+ my $ext = "." . (splitext($file))[1];
+
+ $newFileName .= "." . sprintf($counterSize, $fileCounter) if ($filenameshash{$newFileName . $ext});
+
+ $newFileName .= $ext;
$filenameshash{$newFileName} = $unixTime;
@@ -1633,15 +1630,6 @@ sub template2name {
my $fileName = shift;
my $counterSize = shift;
my $angleSuffix = shift;
- my ($base, $ext); # file name %n and extension %e
-
- if ($fileName =~ m/^(.*)\.([^\.]+)$/) {
- $base = $1;
- $ext = $2;
- } else {
- $base = $fileName;
- $ext = '';
- }
if (not defined $template) {
fatalmsg ("Template isn't given!\n"), die_renrot();
@@ -1658,7 +1646,6 @@ sub template2name {
my $WhiteBalance = "";
my $fileNameOriginal = "";
my $fileNameOriginalCounter = ""; # we can not use 0 as default value
- my $fileNameOriginalExtensionLess = "";
if (defined $infoObj->{"FileNumber"}) {
$FileNumber = $infoObj->{"FileNumber"};
@@ -1695,9 +1682,8 @@ sub template2name {
if ($fileNameOriginal =~ m/^[[:alpha:]\-_]*(\d+)(\.[^\.]+)?$/) {
$fileNameOriginalCounter = $1;
}
- if ($fileNameOriginal =~ m/^(.*)\.([^\.]+)$/) {
- $fileNameOriginalExtensionLess = $1;
- }
+
+ my ($base, $ext) = splitext($fileName); # file name %n and extension %e
my @templatearea = split (//, $template);
my %templatehash = (
@@ -1716,7 +1702,7 @@ sub template2name {
'M' => $tm[5],
'm' => $tm[2],
'n' => $base,
- 'O' => $fileNameOriginalExtensionLess,
+ 'O' => (splitext($fileNameOriginal))[0],
'o' => $fileNameOriginal,
'S' => $tm[6],
'W' => $WhiteBalance,

Return to:

Send suggestions and report system problems to the System administrator.