News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Copy file name and write to tag

Started by A1GSS, June 03, 2015, 08:25:32 AM

Previous topic - Next topic

A1GSS

Hi

Another newbie question. I'm confident that this can be done. My image files (all from scans) have non-date data of interest, which is embedded in the filename. The data I'm interested in consists of some text of variable (but predictable) length being the original media type (eg "Slides" or "Negatives" or "Prints"); a film reference number which is a 12-digit string of the form "NNNN_Film-NN" and a frame number which is always two digits long "NN"

So an example filename looks like this:  Slides 5423 Film_02 02.jpg

So what I want to do is copy the part of the filename before the extension and then write it unaltered into a tag which will have to be created as it will not exist. The name does not need to be transformed. The one that I think will work best is

ImageUniqueID

which takes a string.  So the exiftool command I think is

exiftool '-ImageUniqueID+<filename' DIR

Can it be that simple?  Can't test it just now as I'm busy with "proper" work  :)  but a sanity check welcome.
Graham

StarGeek

Almost.  The plus sign (+) is used to add a value to a list type tag, such as Keywords, or to shift the value of a numeric tag, such as DateTimeOriginal.  For basic text it will respond with a "Warning: Shift value for TAG is not a number" and "Warning: No writable tags set".  So remove that and the command should work.

Since you're just copying the filename, might I suggest IPTC:ObjectName or XMP:Title as I believe that is what those tags are designed for.  ImageUniqueID (and some similar tags) are (I think) used by programs such as Lightroom and if you start using such a program in the future, there may be unexpected results.

Edit:  Sorry, forgot you want to drop the extension.  See this previous post by Phil for a couple of options on removing the extension.
* 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).

A1GSS

Thanks StarGeek, that works without the + sign and takes XMP:Title as the target. It does copy the whole filename including the extension to that tag.

I tried using BaseName:
exiftool '-XMP:Title<BaseName' DIR
but it doesn't change anything ("nn image files unchanged")

Not sure what I'm doing wrong here. I've downloaded, saved and renamed the sample config file which includes the definition for BaseName.






Graham

StarGeek

Take a look at FAQ 11 to see about getting the config file to work.  It makes for a much easier to understand command. 

But if you can't, try this command
exiftool '-XMP:Title<${filename;s/\.[^.]*$//}' DIR
* 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).

A1GSS

Thanks, all seems OK. The bit about environment variables is for Windows, I'm on a Mac. Which specific folder should the config file be in?
Graham

Hayo Baan

The config file should be in your user's home directory (~). Don't forget the leading . in the filename  :)
Hayo Baan – Photography
Web: www.hayobaan.nl

A1GSS

Ah right, not in a subfolder or anything. That's fixed it:

Title                           : Test 1983 Film_06 29

Thanks very much
Graham

A1GSS

Or maybe not.  :(

Just run it again on a whole batch of files and the XMP:Title tag isn't appearing but I've now got one called Base Name. I can live with it (don't mind which tag it uses) but if it's unpredictable that's a bit of a worry.

Base Name                       : Slides 2155 Film_88 27
Graham

Phil Harvey

BaseName is a user-defined Composite tag in the example config file.  It is derived from FileName.

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

A1GSS

Hi Phil, I was wondering why I got the XMP:Title tag in the test I did then Base Name as the tag in the batch which used the same exif command:

exiftool '-XMP:Title<BaseName' -overwrite_original DIR

?
Graham

Phil Harvey

I'm afraid you lost me.  What were the commands and output?

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

A1GSS

Well, I'm aware that this seems unlikely (differing behaviours) so I think I must have done something different, but what I attempted to do was this:

TRIAL RUN
exiftool '-XMP:Title<BaseName' -overwrite_original FILE
produced a tag in the file called "Title" containing the filename without the extension. This was the desired result so I went ahead and ran it
Title                           : Test 1983 Film_06 29


EXECUTION
exiftool '-XMP:Title<BaseName' -overwrite_original DIR
produced a tag in every file called "Base Name" containing the filename without the extension. The XMP tag isn't there at all.
Base Name                       : Slides 2155 Film_88 27

As far as I can tell the files are otherwise identical in that they were all produced by the same scanner and scanning software and have all been similarly touched by exiftool previously to set the createdate etc. The commands were run in Terminal, not script.


Graham

Phil Harvey

Ah.  I think there is some confusion here.

You can't create the BaseName tag.  The difference is that if you have the example config file installed, then the BaseName tag will be generated when extracting information.  So the only remaining question is why (apparently) didn't the second command write the XMP:Title tag?  If it didn't write this, ExifTool should have reported "0 image files updated".

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