Trying to read a filename and parse the values to various custom metadata fields

Started by doubleudet, March 05, 2019, 11:55:55 AM

Previous topic - Next topic

doubleudet

New to EXIFTOOL but I've been meaning to check it out for awhile now. Client request has given me the chance.

Client uses extremely long file names.

Ex: 122618_C_2314_WLB_HotColdTherapyWrap_BackJoint_Overhead.tif

They would like to parse this filename and write to custom WebNative fields as the following:

DisplayDate: 122618
ProductClass: C
ItemCode: 2314
TrademarkAbbreviation: WLB
ProductDescription: HotColdTherapyWrap
Varietal: BackJoint
ShootingDirection: Overhead

I am assuming I would only be able to get up til and including TrademarkAbbreviation because those are known and concistant lengths. ProductDescription will vary and would be next to impossible to extract.

Can I get some help on where to begin though?

Much appreciated

Phil Harvey

It may be easier to do this with user-defined Composite tags, but here is a command that will do it directly (assuming you have defined all of the necessary tags that you want to write):

exiftool -@ my.args DIR

with this my.args file:

-DisplayDate<${filename;my @a=split /_/; $_=$a[0]}
-ProductClass<${filename;my @a=split /_/; $_=$a[1]}
-ItemCode<${filename;my @a=split /_/; $_=$a[2]}
-TrademarkAbbreviation<${filename;my @a=split /_/; $_=$a[3]}
-ProductDescription<${filename;my @a=split /_/; $_=$a[4]}
-Varietal<${filename;my @a=split /_/; $_=$a[5]}
-ShootingDirection<${filename;my @a=split /_/; $_=$a[6]; s/\.[^.]+$//}


All I did was split the filename at each "_".  The only trick was you need to remove the extension from the last one.

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