Skip to content

Commit 03802df

Browse files
norbertwgkmilos
authored andcommitted
rename: path separator for new path based on old path
for concatenation of new file name, concatenation operator of std::filesystem::path is not used: On MSYS2 UCRT64 the path separator to be used in terminal is slash, but as concatenation operator a back slash will be added. Rename works but with verbose a path with different operators will be shown.
1 parent d31fff2 commit 03802df

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

app/actions.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,16 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18281828
return 1;
18291829
}
18301830

1831-
newPath = (p.parent_path() / (basename + p.extension().string())).string();
1831+
// get parent path with separator
1832+
// for concatenation of new file name, concatenation operator of std::filesystem::path is not used:
1833+
// On MSYS2 UCRT64 the path separator to be used in terminal is slash, but as concatenation operator
1834+
// a back slash will be added. Rename works but with verbose a path with different operators will be shown.
1835+
int len = p.parent_path().string().length();
1836+
std::string parent_path_sep = "";
1837+
if (len > 0)
1838+
parent_path_sep = newPath.substr(0, ++len);
1839+
1840+
newPath = parent_path_sep + std::string(basename) + p.extension().string();
18321841

18331842
// rename using exiv2 tags
18341843
// is done after calling setting date/time: the value retrieved from tag might include something like %Y, which then
@@ -1884,8 +1893,7 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18841893
go = false;
18851894
break;
18861895
case Params::renamePolicy:
1887-
newPath = (p.parent_path() / (std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string()))
1888-
.string();
1896+
newPath = parent_path_sep + std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string();
18891897
break;
18901898
case Params::askPolicy:
18911899
std::cout << Params::instance().progname() << ": " << _("File") << " `" << newPath << "' "
@@ -1899,9 +1907,7 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18991907
case 'r':
19001908
case 'R':
19011909
fileExistsPolicy = Params::renamePolicy;
1902-
newPath =
1903-
(p.parent_path() / (std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string()))
1904-
.string();
1910+
newPath = parent_path_sep + std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string();
19051911
break;
19061912
default: // skip
19071913
return -1;

0 commit comments

Comments
 (0)