Main Menu

Substring for Tags?

Started by Archive, May 12, 2010, 08:53:58 AM

Previous topic - Next topic

Archive

[Originally posted by eutychus on 2006-12-14 03:16:22-08]

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.

Archive

[Originally posted by exiftool on 2006-12-14 12:44:50-08]

This can be done with a user-defined tag:

Code:
%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

Archive

[Originally posted by eutychus on 2006-12-14 17:08:44-08]

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!

Archive

[Originally posted by exiftool on 2006-12-14 17:18:51-08]

My apologies.  I should have read your post more closely.  Try this:

Code:
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

Archive

[Originally posted by exiftool on 2006-12-14 17:21:59-08]

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

Archive

[Originally posted by eutychus on 2006-12-14 20:11:53-08]

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.

Archive

[Originally posted by exiftool on 2006-12-14 20:20:25-08]

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

Archive

[Originally posted by eutychus on 2006-12-14 22:24:28-08]

That does it. Thanks!

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

Archive

[Originally posted by eutychus on 2006-12-15 03:55:33-08]

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 :-(

Archive

[Originally posted by exiftool on 2006-12-15 12:16:15-08]

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

Code:
   Writable => 0,

to the tag definition.

I hope this answers your question.

- Phil

Archive

[Originally posted by eutychus on 2006-12-15 18:23:57-08]

It does. Thanks :-)