get rid of suffix
This commit is contained in:
+10
-10
@@ -1972,6 +1972,7 @@ namespace {
|
||||
|
||||
int renameFile(std::string& newPath, const struct tm* tm)
|
||||
{
|
||||
auto p = fs::path(newPath);
|
||||
std::string path = newPath;
|
||||
std::string format = Params::instance().format_;
|
||||
replace(format, ":basename:", Util::basename(path, true));
|
||||
@@ -1986,8 +1987,9 @@ namespace {
|
||||
<< path << "\n";
|
||||
return 1;
|
||||
}
|
||||
newPath = Util::dirname(path) + EXV_SEPARATOR_STR
|
||||
+ basename + Util::suffix(path);
|
||||
|
||||
newPath = p.parent_path() / (basename + p.extension().string());
|
||||
|
||||
if ( Util::dirname(newPath) == Util::dirname(path)
|
||||
&& Util::basename(newPath) == Util::basename(path)) {
|
||||
if (Params::instance().verbose_) {
|
||||
@@ -2008,10 +2010,9 @@ namespace {
|
||||
go = false;
|
||||
break;
|
||||
case Params::renamePolicy:
|
||||
newPath = Util::dirname(path)
|
||||
+ EXV_SEPARATOR_STR + basename
|
||||
+ "_" + Exiv2::toString(seq++)
|
||||
+ Util::suffix(path);
|
||||
newPath = p.parent_path() / (std::string(basename) + "_"
|
||||
+ Exiv2::toString(seq++)
|
||||
+ p.extension().string());
|
||||
break;
|
||||
case Params::askPolicy:
|
||||
std::cout << Params::instance().progname()
|
||||
@@ -2027,10 +2028,9 @@ namespace {
|
||||
case 'r':
|
||||
case 'R':
|
||||
fileExistsPolicy = Params::renamePolicy;
|
||||
newPath = Util::dirname(path)
|
||||
+ EXV_SEPARATOR_STR + basename
|
||||
+ "_" + Exiv2::toString(seq++)
|
||||
+ Util::suffix(path);
|
||||
newPath = p.parent_path() / (std::string(basename) + "_"
|
||||
+ Exiv2::toString(seq++)
|
||||
+ p.extension().string());
|
||||
break;
|
||||
default: // skip
|
||||
return -1;
|
||||
|
||||
@@ -45,10 +45,4 @@ namespace Util {
|
||||
return p.stem().string();
|
||||
return p.filename().string();
|
||||
}
|
||||
|
||||
std::string suffix(const std::string& path)
|
||||
{
|
||||
return fs::path(path).extension().string();
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
|
||||
@@ -57,12 +57,6 @@ namespace Util {
|
||||
*/
|
||||
std::string basename(const std::string& path, bool delsuffix =false);
|
||||
|
||||
/*!
|
||||
@brief Get the suffix from the path string. Normally, the suffix
|
||||
is the substring of the basename of path from the last '.'
|
||||
to the end of the string.
|
||||
*/
|
||||
std::string suffix(const std::string& path);
|
||||
} // namespace Util
|
||||
|
||||
#endif // #ifndef UTILS_HPP_
|
||||
|
||||
@@ -224,36 +224,36 @@ Rename -------------------------------------------------------------------
|
||||
File 1/16: exiv2-empty.jpg
|
||||
exiv2-empty.jpg: No Exif data found in the file
|
||||
File 2/16: exiv2-canon-powershot-s40.jpg
|
||||
Renaming file to ./20031214_000043.jpg
|
||||
Renaming file to 20031214_000043.jpg
|
||||
File 3/16: exiv2-nikon-e990.jpg
|
||||
Renaming file to ./20000506_020544.jpg
|
||||
Renaming file to 20000506_020544.jpg
|
||||
File 4/16: exiv2-nikon-d70.jpg
|
||||
Renaming file to ./20040329_224245.jpg
|
||||
Renaming file to 20040329_224245.jpg
|
||||
File 5/16: exiv2-nikon-e950.jpg
|
||||
Renaming file to ./20010405_235039.jpg
|
||||
Renaming file to 20010405_235039.jpg
|
||||
File 6/16: exiv2-canon-eos-300d.jpg
|
||||
Renaming file to ./20030925_201850.jpg
|
||||
Renaming file to 20030925_201850.jpg
|
||||
File 7/16: exiv2-kodak-dc210.jpg
|
||||
Renaming file to ./20001026_044550.jpg
|
||||
Renaming file to 20001026_044550.jpg
|
||||
File 8/16: exiv2-fujifilm-finepix-s2pro.jpg
|
||||
Renaming file to ./20030926_111535.jpg
|
||||
Renaming file to 20030926_111535.jpg
|
||||
File 9/16: exiv2-sigma-d10.jpg
|
||||
Renaming file to ./20040316_075137.jpg
|
||||
Renaming file to 20040316_075137.jpg
|
||||
File 10/16: exiv2-olympus-c8080wz.jpg
|
||||
Renaming file to ./20040208_093744.jpg
|
||||
Renaming file to 20040208_093744.jpg
|
||||
File 11/16: exiv2-panasonic-dmc-fz5.jpg
|
||||
Renaming file to ./20050218_212016.jpg
|
||||
Renaming file to 20050218_212016.jpg
|
||||
File 12/16: exiv2-sony-dsc-w7.jpg
|
||||
Renaming file to ./20050527_051833.jpg
|
||||
Renaming file to 20050527_051833.jpg
|
||||
File 13/16: exiv2-canon-eos-20d.jpg
|
||||
Warning: Directory Canon has an unexpected next pointer; ignored.
|
||||
Renaming file to ./20060802_095200.jpg
|
||||
Renaming file to 20060802_095200.jpg
|
||||
File 14/16: exiv2-canon-eos-d30.jpg
|
||||
Renaming file to ./20001004_015404.jpg
|
||||
Renaming file to 20001004_015404.jpg
|
||||
File 15/16: exiv2-canon-powershot-a520.jpg
|
||||
Renaming file to ./20060127_225027.jpg
|
||||
Renaming file to 20060127_225027.jpg
|
||||
File 16/16: exiv2-photoshop.psd
|
||||
Renaming file to ./20110627_094001.psd
|
||||
Renaming file to 20110627_094001.psd
|
||||
|
||||
Print --------------------------------------------------------------------
|
||||
File 1/16: exiv2-empty.jpg
|
||||
|
||||
@@ -26,10 +26,6 @@ TEST(basename, returnsStemWithoutExtensionWithValidPathOnWindows)
|
||||
const bool delSuffix = true;
|
||||
ASSERT_EQ("file", Util::basename(pathWindows, delSuffix));
|
||||
}
|
||||
TEST(suffix, returnsExtensionWithValidWindowsPath)
|
||||
{
|
||||
ASSERT_EQ(".txt", Util::suffix(pathWindows));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -63,17 +59,4 @@ TEST(basename, returnsStemWithoutExtensionWithValidPathOnLinux)
|
||||
ASSERT_EQ("file", Util::basename(pathLinux, delSuffix));
|
||||
}
|
||||
|
||||
|
||||
TEST(suffix, returnsExtensionWithValidLinuxPath)
|
||||
{
|
||||
ASSERT_EQ(".txt", Util::suffix(pathLinux));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
TEST(suffix, returnsEmptyStringWithFilesWithoutExtension)
|
||||
{
|
||||
ASSERT_EQ("", Util::suffix("/home/luis/file"));
|
||||
ASSERT_EQ("", Util::suffix("c:\\luis\\file"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user