Composite tag to convert whitespace to _ except trailing or leading whitespace

Started by empedia, February 15, 2013, 12:44:39 PM

Previous topic - Next topic

empedia

Hi,

I am trying to use the rename functionality to rename some files based on the value of the tag but the value of the tag sometimes has one or more trailing spaces or leading spaces in it.

I need to convert any spaces in the body of the tag value to underscore but I also want to get rid of any trailing  or leading whitespace completely.

I understand I need to create a user-defined (composite) tag to do this but I don't have the knowledge of Perl substitution to know how to specify the expression I need to achieve this.

Can anyone help?

Many thanks,

Matthew.

Phil Harvey

Hi Matthew,

As of ExifTool 9.15 you can now do this with an advanced formatting expression.  Specifically, this command should do what you want:

exiftool "-filename<${TAG;s/(^\s+|\s+$)//g;tr/ /_/}.%e" FILE

where TAG is your tag name, and FILE is one or more directory or file names.  The above quoting is for Windows.  Use single quotes instead if you are on Mac or Linux.

- Phil

Edit: Fixed a couple of slashes that should have been backslashes
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).