Skip to content

Commit

Permalink
placeholder basesuffix for rename format
Browse files Browse the repository at this point in the history
  • Loading branch information
norbertwg authored and neheb committed Sep 26, 2023
1 parent fc7d570 commit 1ff5560
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
1 change: 1 addition & 0 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 12 additions & 5 deletions exiv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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```
<div id="adjust_time">
### **-a** *time*, **--adjust** *time*
Expand Down
1 change: 1 addition & 0 deletions test/data/test_reference_files/exiv2-test.out
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Options:
-r fmt Filename format for the 'rename' action. The format string
follows strftime(3). The following keywords are also supported:
: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
:parentname: - name of parent directory
Default 'fmt' is %Y%m%d_%H%M%S
Expand Down

0 comments on commit 1ff5560

Please sign in to comment.