diff --git a/app/actions.cpp b/app/actions.cpp index 7678a5df..284a2979 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -1826,7 +1826,13 @@ int renameFile(std::string& newPath, const tm* tm) { std::string path = newPath; auto oldFsPath = fs::path(path); std::string format = Params::instance().format_; + std::string filename = p.stem().string(); + std::string basesuffix = ""; + int pos = filename.find('.'); + if (pos > 0) + basesuffix = filename.substr(filename.find('.')); replace(format, ":basename:", p.stem().string()); + replace(format, ":basesuffix:", basesuffix); replace(format, ":dirname:", p.parent_path().filename().string()); replace(format, ":parentname:", p.parent_path().parent_path().filename().string()); diff --git a/app/exiv2.cpp b/app/exiv2.cpp index a35ead58..f197800b 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -334,6 +334,7 @@ void Params::help(std::ostream& os) const { << _(" -r fmt Filename format for the 'rename' action. The format string\n") << _(" follows strftime(3). The following keywords are also supported:\n") << _(" :basename: - original filename without extension\n") + << _(" :basesuffix: - suffix in original filename, starts with first dot and ends before extension\n") << _(" :dirname: - name of the directory holding the original file\n") << _(" :parentname: - name of parent directory\n") << _(" Default 'fmt' is %Y%m%d_%H%M%S\n") << _(" -c txt JPEG comment string to set in the image.\n") diff --git a/exiv2.md b/exiv2.md index 99bd3737..82bb6f3d 100644 --- a/exiv2.md +++ b/exiv2.md @@ -455,11 +455,12 @@ environment variable). The *fmt* string follows the definitions in date and time. In addition, the following special character sequences are also provided: -| Variable | Description | -|:------ |:---- | -| :basename: | Original filename without extension | -| :dirname: | Name of the directory holding the original file | -| :parentname: | Name of parent directory | +| Variable | Description | +|:------ |:---- | +| :basename: | Original filename without extension | +| :basesuffix: | Suffix in original filename, starts with first dot and ends before extension, e.g. PANO, MP, NIGHT added by Google Camera app | +| :dirname: | Name of the directory holding the original file | +| :parentname: | Name of parent directory | The default *fmt* is %Y%m%d_%H%M%S @@ -491,6 +492,12 @@ exiv2.exe: File `./Stonehenge_16_Jul_2015.jpg' exists. [O]verwrite, [r]ename or Renaming file to ./Stonehenge_16_Jul_2015_1.jpg ``` +If the filename contains a suffix, which shall be included in new filename: +``` +$ exiv2 --verbose --rename '%d_%b_%Y:basesuffix:' Stonehenge.PANO.jpg +File 1/1: Stonehenge.PANO.jpg +Renaming file to '16_Jul_2015.PANO'.jpg``` +