ExifTool Forum

ExifTool => Newbies => Topic started by: lnjustin on October 19, 2019, 03:21:52 PM

Title: Regular Expression for renaming file?
Post by: lnjustin on October 19, 2019, 03:21:52 PM
I need to rename files that are (accidentally) named like:
2016-11-11_at_22h55m00056.MTS
YYYY-MM-DD_at_HHhMMmXXXXX.MTS

I need to extract the XXXXX (the last 5 characters before the period/extension). And then rename to:
YYYY-MM-DD_at_HHhMMmSSs_XXXXX.MTS (the seconds need to be added after the minutes)

So it would look more like
2016-11-11_at_22h55m45s_00056.MTS

I know how to do what i need if I would run this on the original file named 00056.MTS. It would be:
/usr/local/bin/exiftool -d /Volumes/video/%Y/%m/%Y-%m-%d_at_%Hh%Mm$Ss_%%f.%%e '-filename<DateTimeOriginal' filename

But now that I ran this command once with the wrong format, I need another command that will simply rename the file. But I don't know how to use regular expressions for this. Help?
Title: Re: Regular Expression for renaming file?
Post by: StarGeek on October 19, 2019, 03:42:48 PM
One of the advanced options for the %f variable is to grab characters from the end of the filename (excluding the extension).  So try your normal command but instead of %%f, try %%-5f.  Use TestName instead of Filename to test without making changes.
Title: Re: Regular Expression for renaming file?
Post by: e2b on October 20, 2019, 01:29:37 AM
Where are the advanced options for the %f variable documented, please?
Title: Re: Regular Expression for renaming file?
Post by: StarGeek on October 20, 2019, 01:54:24 AM
The percent variables are documented under the -w (textout) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut).
Title: Re: Regular Expression for renaming file?
Post by: e2b on October 20, 2019, 09:16:13 AM
Thanks!