ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: PolarSeven on June 01, 2018, 08:16:55 AM

Title: Exif newbie
Post by: PolarSeven on June 01, 2018, 08:16:55 AM
Hi all,

Apologies in advance for my basic query (I have searched for an answer on these forums but I could not spot it!)


I know this uses wildcards and text formatting and I am not great at these - any resources on these would be amazing. Thank you for any help you can offer.
Title: Re: Exif newbie
Post by: Phil Harvey on June 01, 2018, 08:47:13 AM
This involves some fairly advanced operations.  Try this on a test directory to see if it does what you want:

exiftool "-originalfilename<filename" "-filename<${filename;/(\d+)/ ? $1 : undef}.%e" "-headline<${filename;s/.*?\d+_//;s/(.*)\..*/$1/;tr/_/ /}" DIR

Note that I am also writing OriginalFileName to preserve the original name in case you need it later.

To explain some things:

${filename;/(\d+)/ ? $1 : undef}.%e

- takes only the first string of digits from the file name, then adds back the extension (.%e).

${filename;s/.*?\d+_//;s/(.*)\..*/$1/;tr/_/ /}

- removes everything up to and including the first set of digits plus an underscore, then removes the file extension and translates underlines to spaces.

Read about Perl regular expressions (https://www.regular-expressions.info) if you want to learn more about how this was done.

- Phil
Title: Re: Exif newbie
Post by: PolarSeven on June 01, 2018, 09:38:29 AM
Hi Phil,

This is amazing thanks!

The headline part works great but the filename is duplicating and adding a second extension e.g. .jpg.jpg

I will certainly check the article. Thanks for your help, very much appreciated.
Title: Re: Exif newbie
Post by: Phil Harvey on June 01, 2018, 09:56:49 AM
Ah, right.  Sorry.  Try this:

exiftool "-originalfilename<filename" "-filename<${filename;$_ = /(\d+)/ ? $1 : undef}.%e" "-headline<${filename;s/.*?\d+_//;s/(.*)\..*/$1/;tr/_/ /}" DIR

I forgot to set $_ to the result of the condition.  In ExifTool advanced formatting expressions, you modify the default variable ($_) to change the value.

- Phil
Title: Re: Exif newbie
Post by: PolarSeven on June 01, 2018, 10:18:39 AM
Hi Phil,

Getting a bad substitution warning now.

Honestly Phil if it is advanced/tricky I don't want to take up any more of your time. I'll find a workaround that doesn't require that hard a line of code (for me!)
Title: Re: Exif newbie
Post by: Phil Harvey on June 01, 2018, 10:29:39 AM
Adding "$_ =" shouldn't have caused a "bad subsitution" warning.  Something else must have changed.  Can you paste in the command line you used, showing the warning?

Don't worry about wasting my time.  We should be really close to a solution.

I doubt that you'll find any other solution that will do exactly what you want this easily.

- Phil
Title: Re: Exif newbie
Post by: PolarSeven on June 01, 2018, 10:35:57 AM
Hi Phil,

Again thanks.

I get two errors - first filename not found. This goes away when I remove the original filename protection and then bad sub
Title: Re: Exif newbie
Post by: Phil Harvey on June 01, 2018, 10:39:03 AM
You need a space before /Users/font/Desktop/Test

Also, use plain ASCII single quotes ('), not the funny quotes you are using.

- Phil
Title: Re: Exif newbie
Post by: PolarSeven on June 01, 2018, 11:05:11 AM
Thanks! That worked.

No idea why the odd quotes appeared (standard Mac single quote on extended keyboard). I copied your quotes and it worked.