ExifTool Forum

ExifTool => Newbies => Topic started by: A1GSS on June 03, 2015, 08:25:32 AM

Title: Copy file name and write to tag
Post by: A1GSS on June 03, 2015, 08:25:32 AM
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.
Title: Re: Copy file name and write to tag
Post by: StarGeek on June 03, 2015, 12:12:43 PM
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 (https://exiftool.org/forum/index.php/topic,6192.msg30588.html#msg30588) by Phil for a couple of options on removing the extension.
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 04, 2015, 02:42:27 AM
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.






Title: Re: Copy file name and write to tag
Post by: StarGeek on June 04, 2015, 03:21:49 AM
Take a look at FAQ 11 (http://www.exiftool.org/faq.html#Q11) 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
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 04, 2015, 06:10:39 AM
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?
Title: Re: Copy file name and write to tag
Post by: Hayo Baan on June 04, 2015, 06:29:45 AM
The config file should be in your user's home directory (~). Don't forget the leading . in the filename  :)
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 04, 2015, 07:07:42 AM
Ah right, not in a subfolder or anything. That's fixed it:

Title                           : Test 1983 Film_06 29

Thanks very much
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 04, 2015, 07:56:49 AM
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
Title: Re: Copy file name and write to tag
Post by: Phil Harvey on June 04, 2015, 07:58:26 AM
BaseName is a user-defined Composite tag in the example config file.  It is derived from FileName.

- Phil
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 04, 2015, 08:12:10 AM
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

?
Title: Re: Copy file name and write to tag
Post by: Phil Harvey on June 05, 2015, 06:58:32 AM
I'm afraid you lost me.  What were the commands and output?

- Phil
Title: Re: Copy file name and write to tag
Post by: A1GSS on June 05, 2015, 07:36:21 AM
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.


Title: Re: Copy file name and write to tag
Post by: Phil Harvey on June 05, 2015, 08:07:01 AM
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