Can exiftool extract portions of the filename?

Started by vbnut, April 13, 2025, 09:06:48 PM

Previous topic - Next topic

vbnut

I use a PowerShell script to ingest images and videos from a memory card to a storage volume on my computer, using exiftool to do the copy, organize them into the same date-based folders and rename them to my personal naming scheme.  This has been working well for a couple of years, but I recently purchased an R5 Mark II, and while the script still works fine for images, videos are a different story. Instead of naming video files similar to images, but with the suffix .mp3, like the R3 did, the R5II uses a more complicated file naming scheme for videos (described here), so my renaming scheme isn't working well for these video files, and I'm trying to decide how to fix it.  As far as I can tell, the various items embedded into the file name are not replicated in the metadata by the camera.

Can exiftool do pattern matching on the filename, perhaps using a regular expression, so that I can write the items in metadata tags and/or create a new file name using some of the items?

StarGeek

Quote from: vbnut on April 13, 2025, 09:06:48 PMCan exiftool do pattern matching on the filename, perhaps using a regular expression, so that I can write the items in metadata tags and/or create a new file name using some of the items?

Yes. The file name is considered a tag, and can be manipulated using any standard Perl function, including regex.

For example, in this post, the YearDateMonth in a filename from WhatsApp are extracted, then set to the Perl default variable to allow writing date/time data into the EXIF time stamps.

It could also be done with Perl regex substitution along these lines
${Filename;s/.*(\d{8}).*/$1/}

Search these forums for "filename regex" to find many examples.

Your main problem, though, is dealing with dollar signs and quoting in PowerShell. The image in this post shows how to quote an exiftool command in CMD and then Mac/Linux. Neither of these commands will work in PowerShell. So you will have to figure out how to make it work, as I can't help with PS.
"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

vbnut

That's great.  Thanks for the info.  I had a 40-year career as a software engineer, and I managed to solve all the quoting issues for my existing -dateFormat parameters (no dollar signs though), so I'm pretty sure I'll be able to figure how to make the regex stuff work in Powershell.  Looks like I get to spend more time in quoting hell :)