Thread

Posted on Thu Dec 14 05:16:22 2006 by eutychus
Substring for Tags?
Is it possible to grab just a portion of a tag? I know it can be done with parts of file names and directory names, but I can't figure out how to do it for tags. I'd like to use the last 4 characters of the "file number" tag as part of a new file name.
Direct Responses: 3764 | Write a response
Posted on Thu Dec 14 14:44:50 2006 by exiftool in response to 3760
Re: Substring for Tags?
This can be done with a user-defined tag:
%Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { MyFileNumber => { Require => { 0 => 'FileNumber', }, ValueConv => 'length($prt[0]) > 4 ? substr($prt[0], 0, 4) : undef', }, }, );

I think this will do what you want. Here I define a "MyFileNumber" tag which is the first 4 characters of the FileNumber value. I have assumed that you want the '-' as the 4th character, so I used the PrintConv value ('prt') instead of the ValueConv value ('val') (the '-' is inserted by the print conversion. If you don't understand what I am talking about, try extracting FileNumber with the -n option).

config file documentation for details on how to set up user-defined tags.

- Phil
Direct Responses: 3780 | Write a response
Posted on Thu Dec 14 19:08:44 2006 by eutychus in response to 3764
Re: Substring for Tags?

I think that's getting close. I actually want the last 4 characters, not the first 4. So, inserting the '-' is unnecessary. I do understand what you mean by that, though. I've never used PERL, but I could probably figure out how to modify your code . . . unless you have time to do it for me :-)

Also, I'm using the Windows exiftool.exe file. Would I put the config file in the same directory as the exiftool.exe file? I have that directory in my path. Or, do I have to use the PERL modules?

Thanks!

Direct Responses: 3782 | Write a response
Posted on Thu Dec 14 19:18:51 2006 by exiftool in response to 3780
Re: Substring for Tags?
My apologies. I should have read your post more closely. Try this:

ValueConv => 'length($val[0]) > 4 ? substr($val[0], -4) : $val[0]',

I also tweaked a couple of other things when I changed it to use the last 4 characters.

- Phil
Direct Responses: 3783 | Write a response
Posted on Thu Dec 14 19:21:59 2006 by exiftool in response to 3782
Re: Substring for Tags?
And to answer your second question: It should work if you put the ".ExifTool_config" file in the same directory as "exiftool.exe". (in theory anyway, I haven't played with config files for the .exe version myself yet)

- Phil
Direct Responses: 3787 | Write a response
Posted on Thu Dec 14 22:11:53 2006 by eutychus in response to 3783
Re: Substring for Tags?
Arrggh. Unfortunately, Windows won't allow files that have no name. It treats everything after the '.' as an extension; so it thinks this file has no name, just an extension. That's a bit different from Unix. So, I can't properly name the file so that Windows will allow it and Exiftool will recognize it. Any ideas? What do people do who are using PERL under Windows and want to have this config file? Perhaps the same solution would work.
Direct Responses: 3788 | Write a response
Posted on Thu Dec 14 22:20:25 2006 by exiftool in response to 3787
Re: Substring for Tags?
It should work if you rename it from the command line. (ie. fire up cmd.exe and type something like "rename ExifTool_config .ExifTool_config".)

Good luck!

- Phil
Direct Responses: 3793 | Write a response
Posted on Fri Dec 15 00:24:28 2006 by eutychus in response to 3788
Re: Substring for Tags?

That does it. Thanks!

Oh, the config file does work with the windows .exe

Direct Responses: 3801 | Write a response
Posted on Fri Dec 15 05:55:33 2006 by eutychus in response to 3793
Re: Substring for Tags?
Follow-up: Is there a way to define that new tag so that it doesn't get written to the file? I tried to figure out how to do it as a shortcut and/or a composite tag, both of which I assume would only be "virtual" tags, but I couldn't get them to work. I'd really like to use that new tag only in a "virtual" way to help me rename my files, but I don't want it to end up in the files themselves. Is that possible? I tried to follow the examples in the documentation, but I couldn't get them to work. Sorry . . . probably my fault :-(
Direct Responses: 3806 | Write a response
Posted on Fri Dec 15 14:16:15 2006 by exiftool in response to 3801
Re: Substring for Tags?
Sure. Shortcut tags are not written themselves, but if they reference writable tags, the shortcuts may be used to write these tags.

Composite tags are not writable.

And you can prevent other user-defined tags from being written by adding

Writable => 0,

to the tag definition.

I hope this answers your question.

- Phil
Direct Responses: 3814 | Write a response
Posted on Fri Dec 15 20:23:57 2006 by eutychus in response to 3806
Re: Substring for Tags?
It does. Thanks :-)
Write a response