[resolved] Rename files with specific OffsetTime format

Started by berebin, November 14, 2023, 10:37:43 AM

Previous topic - Next topic

berebin

Hey, everybody!

I am trying to rename photos using the pattern "YYYYYYMMDD_HHMMSS_gmtOFFSET.ext", where OFFSET is 4 characters (4 digits) for positive offset or 5 characters (minus sign and 4 digits) for negative offset. For example:

  • 20231114_202653_gmt0500.HEIC
  • 20231112_091528_gmt0300.HEIC
  • 20231110_171736_gmt-0100.HEIC

At the terminal on macOS, I do the following:

exiftool '-testname<${DateTimeOriginal}_gmt${OffsetTime}.%e' -d '%Y-%m-%d_%H-%M-%S%' .

As a result, I get the characters "plus" and "colon" in the offset part:

  • 20231114_202653_gmt+05:00.HEIC
  • 20231112_091528_gmt+03:00.HEIC
  • 20231110_171736_gmt-01:00.HEIC

Is there an option to set a formatting pattern for the OffsetTime tag? Or perhaps there is another way to solve the problem?

StarGeek

Try using
${OffsetTime;s/[+:]//g}

This will remove any + or : in the offset time tag.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

berebin

Quote from: StarGeek on November 14, 2023, 10:47:40 AMTry using
${OffsetTime;s/[+:]//g}

This will remove any + or : in the offset time tag.
StarGeek, you made my evening! Thank you for the quick reply.

Phil Harvey

Just a very minor point, but using tr/// (translate) instead of s/// (substitute) is a more efficient way to remove characters:

${OffsetTime;tr/+://d}

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

berebin

Quote from: Phil Harvey on November 14, 2023, 12:31:46 PMJust a very minor point, but using tr/// (translate) instead of s/// (substitute) is a more efficient way to remove characters:

${OffsetTime;tr/+://d}

- Phil

Phil, thank you for your reply as well!