aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andy@smile.org.ua>2012-07-29 08:47:33 +0000
committerAndy Shevchenko <andy@smile.org.ua>2012-07-29 08:47:33 +0000
commit388814857c45c9076d88da6eb89c7180e9b7dbfd (patch)
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
-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
@@ -17,3 +17,3 @@ use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
-@EXPORT = qw(makedir);
+@EXPORT = qw(makedir splitext);
@@ -152,2 +152,9 @@ sub piper {
+sub splitext {
+ my $filename = shift;
+
+ return ($1, $2) if ($filename =~ m/(.*)\.([^\/\.]+)$/);
+ return ($filename, "");
+}
+
########################################################################################
diff --git a/renrot b/renrot
index 8d4c599..ea0f97b 100755
--- a/renrot
+++ b/renrot
@@ -748,5 +748,2 @@ sub renameFile {
} else {
- my $ext = ($file =~ m/(\.[^\.]+)$/) ? $1 : "";
- my $extLen = length($ext);
-
$newFileName = template2name (
@@ -761,7 +758,7 @@ sub renameFile {
- 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;
@@ -1635,11 +1632,2 @@ sub template2name {
my $angleSuffix = shift;
- my ($base, $ext); # file name %n and extension %e
-
- if ($fileName =~ m/^(.*)\.([^\.]+)$/) {
- $base = $1;
- $ext = $2;
- } else {
- $base = $fileName;
- $ext = '';
- }
@@ -1660,3 +1648,2 @@ sub template2name {
my $fileNameOriginalCounter = ""; # we can not use 0 as default value
- my $fileNameOriginalExtensionLess = "";
@@ -1697,5 +1684,4 @@ sub template2name {
}
- if ($fileNameOriginal =~ m/^(.*)\.([^\.]+)$/) {
- $fileNameOriginalExtensionLess = $1;
- }
+
+ my ($base, $ext) = splitext($fileName); # file name %n and extension %e
@@ -1718,3 +1704,3 @@ sub template2name {
'n' => $base,
- 'O' => $fileNameOriginalExtensionLess,
+ 'O' => (splitext($fileNameOriginal))[0],
'o' => $fileNameOriginal,

Return to:

Send suggestions and report system problems to the System administrator.