diff options
author | Andy Shevchenko <andy@smile.org.ua> | 2012-07-29 08:47:33 +0000 |
---|---|---|
committer | Andy Shevchenko <andy@smile.org.ua> | 2012-07-29 08:47:33 +0000 |
commit | 388814857c45c9076d88da6eb89c7180e9b7dbfd (patch) | |
tree | 03f46eeda6585286e16fdfd1bc3b18d2f94f0252 | |
parent | d7282126855b13df51fab62b97f50678cbfd4d41 (diff) | |
download | renrot-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.pm | 9 | ||||
-rwxr-xr-x | renrot | 30 |
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, ""); +} + ######################################################################################## @@ -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, |