placeholder basesuffix for rename format

main
norbertwg 2 years ago committed by Rosen Penev
parent fc7d570207
commit 1ff5560d36

@ -1826,7 +1826,13 @@ int renameFile(std::string& newPath, const tm* tm) {
std::string path = newPath; std::string path = newPath;
auto oldFsPath = fs::path(path); auto oldFsPath = fs::path(path);
std::string format = Params::instance().format_; 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, ":basename:", p.stem().string());
replace(format, ":basesuffix:", basesuffix);
replace(format, ":dirname:", p.parent_path().filename().string()); replace(format, ":dirname:", p.parent_path().filename().string());
replace(format, ":parentname:", p.parent_path().parent_path().filename().string()); replace(format, ":parentname:", p.parent_path().parent_path().filename().string());

@ -334,6 +334,7 @@ void Params::help(std::ostream& os) const {
<< _(" -r fmt Filename format for the 'rename' action. The format string\n") << _(" -r fmt Filename format for the 'rename' action. The format string\n")
<< _(" follows strftime(3). The following keywords are also supported:\n") << _(" follows strftime(3). The following keywords are also supported:\n")
<< _(" :basename: - original filename without extension\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") << _(" :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") << _(" :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") << _(" -c txt JPEG comment string to set in the image.\n")

@ -458,6 +458,7 @@ also provided:
| Variable | Description | | Variable | Description |
|:------ |:---- | |:------ |:---- |
| :basename: | Original filename without extension | | :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 | | :dirname: | Name of the directory holding the original file |
| :parentname: | Name of parent directory | | :parentname: | Name of parent directory |
@ -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 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```
<div id="adjust_time"> <div id="adjust_time">
### **-a** *time*, **--adjust** *time* ### **-a** *time*, **--adjust** *time*

@ -140,6 +140,7 @@ Options:
-r fmt Filename format for the 'rename' action. The format string -r fmt Filename format for the 'rename' action. The format string
follows strftime(3). The following keywords are also supported: follows strftime(3). The following keywords are also supported:
:basename: - original filename without extension :basename: - original filename without extension
:basesuffix: - suffix in original filename, starts with first dot and ends before extension
:dirname: - name of the directory holding the original file :dirname: - name of the directory holding the original file
:parentname: - name of parent directory :parentname: - name of parent directory
Default 'fmt' is %Y%m%d_%H%M%S Default 'fmt' is %Y%m%d_%H%M%S

Loading…
Cancel
Save