Author Topic: Copy file name and write to tag  (Read 3984 times)

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Copy file name and write to tag
« 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.
Graham

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: Copy file name and write to tag
« Reply #1 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 by Phil for a couple of options on removing the extension.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #2 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.

 




Graham

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: Copy file name and write to tag
« Reply #3 on: June 04, 2015, 03:21:49 AM »
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
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #4 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?
Graham

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 925
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: Copy file name and write to tag
« Reply #5 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  :)
Hayo Baan – Photography
Web: www.hayobaan.nl

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #6 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
Graham

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #7 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
Graham

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Copy file name and write to tag
« Reply #8 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #9 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

?
Graham

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Copy file name and write to tag
« Reply #10 on: June 05, 2015, 06:58:32 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

A1GSS

  • Jr. Member
  • **
  • Posts: 18
Re: Copy file name and write to tag
« Reply #11 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.


Graham

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Copy file name and write to tag
« Reply #12 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).