Filename to {Title} and multiple other datafields Possible?

Started by Trailboy, September 03, 2019, 04:36:06 AM

Previous topic - Next topic

Trailboy

Hi. 

I've so far been using the following code in the target of the shortcut

C:\Windows\exiftool.exe "-xmp-dc:Title<basename" "-iptc:caption-abstract<basename" -overwrite_original pause

to get the complete filename into the {title} and {caption} exiffield of my images. 

Is it possible to split the filename over multiple exif fields, e.g.

Sample Filename:  aa20abcd-000123-1-FirstnameSurname

Split into

{Title}:  aa20abcd
{Instructions}:  000123
{Source}:  1
{Job Identifier}:  FirstnameSurname

FirstnameSurname is the only variable length data, which is why it's at the end.   

I've been using a .lua script to perform this function in Lightroom, but need it working in exiftool if possible?

Is it possible?

Thanks all.








StarGeek

Yes, very much possible.  Especially for fixed length fields.  I'm making the the assumption that Instructions and Source are always numeric, let me know if that's wrong.

Each item can be extracted as follows:
${Basename;m/^(.{8})/;$_=$1}
${Basename;m/^.{8}-(\d{6})/;$_=$1}
${Basename;m/^.{8}-.{6}-(\d)/;$_=$1}
${Basename;m/^.{18}(.*)/;$_=$1}

Simply take the part you want and do the same thing as you did Basename to place it in the field you want, e.g. "-Title<${Basename;m/^(.{8})/;$_=$1}"

Example output.  Ignore the $/ in the command, those are used by the -p (printFormat) option as new lines.
C:\>exiftool -config example.config "Y:\!temp\yy\aa20abcd-000123-1-FirstnameSurname.jpg" -p " ${Basename;m/^(.{8})/;$_=$1} $/ ${Basename;m/^.{8}-(\d{6})/;$_=$1} $/ ${Basename;m/^.{8}-.{6}-(\d)/;$_=$1} $/ ${Basename;m/^.{18}(.*)/;$_=$1} "
aa20abcd
000123
1
FirstnameSurname
"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

Trailboy

My goodness, thank you StarGeek!

I'm busy for the next few days, so please forgive me if I don't manage to work on this for a short time and come back with some more questions. 

But I'm really pleased this is possible. Will make my life a lot easier.

Re Numeric fields - Instructions are always numeric (unique ID in DB), but source could be alphanumeric and I should have made it 2 characters rather than 1 (actually it's the school class code, so it could be 01, 02, or even r1 for reception or Nu for nursery for example). 

Thanks again! 





 


StarGeek

Quote from: Trailboy on September 04, 2019, 04:06:05 AMbut source could be alphanumeric and I should have made it 2 characters rather than 1 (actually it's the school class code, so it could be 01, 02, or even r1 for reception or Nu for nursery for example). 

Ok, then to refine that further, for a source with two alphanumeric characters (and underscore)
${Basename;m/^.{8}-.{6}-(\w\w)-/;$_=$1}
and to be complete, a source with either one or two
${Basename;m/^.{8}-.{6}-(\w\w?)-/;$_=$1}
"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

Trailboy

Just like to say thank you to Stargeek for helping me out with this.  Attachment shows it working fine. 

This code


C:\Windows\exiftool.exe "-xmp-dc:Title<${Basename;m/^(.{8})/;$_=$1}" "-iptc:SpecialInstructions<${Basename;m/^.{8}-(\d{6})/;$_=$1}" "-iptc:source<${Basename;m/^.{8}-.{6}-(\d)/;$_=$1}" "-iptc:caption-abstract<${Basename;m/^.{18}(.*)/;$_=$1}" -overwrite_original pause


works just fine for me. 

Strangely, my desktop shortcut appears to truncate the line.  It still seems to work though.  Is there a maximum line length when using a windows desktop shortcut? 

It truncates to:


C:\Windows\exiftool.exe "-xmp-dc:Title<${Basename;m/^(.{8})/;$_=$1}" "-iptc:SpecialInstructions<${Basename;m/^.{8}-(\d{6})/;$_=$1}" "-iptc:source<${Basename;m/^.{8}-.{6}-(\d)/;$_=$1}" "-iptc:caption-abstract<${Basename;m/^.{18}(.*)/;$_=$1}" -overwrite_origina





StarGeek

Quote from: Trailboy on October 11, 2019, 12:29:43 PMIs there a maximum line length when using a windows desktop shortcut? 

A quick google shows that the shortcut has a maximum length of 260 characters and your command is a few characters over that.  It appears to be cutting off the Overwrite_Original option.  Are you sure that the _original backup files aren't being created?

"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

thundt

In case somebody else comes here looking for ways to chop up filenames:  I used the `split` function as follows, to cut up a filename into fragments delimited by blanks.  (I was dealing with filenames like `70242146984__58C7C56B-4E30-4D69-9191-6540A3225B33 fixed door top corner.HEIC`)
# repl first fragment of filename w/ local timestamp
# (removes first fragment of filename -- ugly GUID etc.)
exiftool '-TestName<${FileModifyDate} ${FileName;$_=(split /\s+/,$_,2)[1] || $_}' \
    -d %Y%m%d_%H%M%S *.HEIC