Problem Removing Characters From Filename To Title

Started by MyFootSmellsFunny, July 17, 2018, 11:16:27 AM

Previous topic - Next topic

MyFootSmellsFunny

Hello I am completely new to programming and to the ExifTool in general.

Here is my dilemma:

I need to take part of the name of a JPG and put it as the Title in the properties field of the file but I need to omit the photo's incremental indicator and the extension. Example below:
Picture name examples:
JPG name: 1970 Mustang Mach 1 (1).JPG
JPG name: 1970 Mustang Mach 1 (2).JPG
JPG name: 1970 Mustang Mach 1 (3).JPG
JPG name: 1970 Mustang Mach 1 (4).JPG
JPG name: 1970 Mustang Mach 1 (5).JPG

The pictures are named the same due to the subject and for quick referencing.

I have this command that will do everything I need except it keeps the (1),(2), so on and so on in the Title of the JPEG file.

Here's the command I have been using and then going back and manually cleaning up the titles one by one through Windows: exiftool "-Title<${Filename;s/\.[^.]*$//}" . However now I am needing to do this to about 2000-7000 pictures so manually it would be hours and hours worth of work. That's why I came to the pros for help  8)

It took me hours to figure that command out using bits and pieces here and there from other sites and postings but I have been working on removing the photo's increment for about 2 weeks with no success.

Any help with this would be muchly appreciated. Thanks

Phil Harvey

Try this:

exiftool "-title<${filename;s/\.[^.]*$//;s/ \(.*//}" DIR

I have left in your expression to strip off the extension for files that don't have the copy number.

- 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 ($).

MyFootSmellsFunny

AWESOME THANK YOU SO MUCH!!!!!!!! I love this tool! Thank you for creating it!! You just saved me hours and hours of work!!!!

Stephen Marsh

Quote from: Phil Harvey on July 17, 2018, 11:23:50 AM
Try this:

exiftool "-title<${filename;s/\.[^.]*$//;s/ \(.*//}" DIR

I have left in your expression to strip off the extension for files that don't have the copy number.

- Phil

Hang on, did you just do what I thought Phil?

One can just chain together multiple regex search/replaces – rather than building a potentially more complex single regex to achieve the same end? And you used an explicit word space, rather than a generic white space \s

? ? ?

I see new possibilities!

exiftool "-title<${filename;s/(^.+)(\s\(.+\)\.[^.]*$)/$1/}" DIR



StarGeek

Quote from: Stephen Marsh on July 29, 2018, 09:47:10 AM
One can just chain together multiple regex search/replaces

Should I not mention that the first example under Advanced formatting feature shows chaining two commands?  ;)  Admittedly, it's a tr and a regex substitution, but it's the same concept.  You do have to remember that they will be processed sequentially, so if your first expression creates something that will be matched in the second expression, then it will be affected by the second expression.

QuoteAnd you used an explicit word space, rather than a generic white space \s

Yep, useful when you want to reduce extra spaces.  For example:  s/  +/ /g (two spaces in the search part) will reduce two or more spaces into a single space without affecting other whitespaces such as tabs.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).