ExifTool Forum

ExifTool => Newbies => Topic started by: ezeeckiel on April 15, 2013, 06:05:06 AM

Title: Writing Userdefined Tag with filename
Post by: ezeeckiel on April 15, 2013, 06:05:06 AM
Dear Phil,

Thanks a lot for this amazing tool i'm discovering. It seems perfect to handle the files I have. My goal is to add userdefined tags to my files so later on I could seek through them with queries like: give me the jpg files where userdefined1=value, etc...

Now I'm struggling with the command line
All files in directory are written so :
name1_01.jpg
name1_02.jpg
name2_01.jpg
name3_01.jpg
...


What I would like to do is :
for all files in a directory
add newEXIFTag
and fill it with nameX

I can't figure how to write the -NewEXIFTag=%f??

Also, I'm a bit confused about how to use the batch mode. It seems for me that some operation needs a .bat file written as so :
#!/bin/bash
exiftool command line

and some others don't. If you could clarify this point, i should be able to understand better (if needed)
cheers
Olivier
Title: Re: Writing Userdefined Tag with filename
Post by: Phil Harvey on April 15, 2013, 06:13:01 AM
Hi Olivier,

The command is:

exiftool "-userdefined1<basename" "-userdefined2<basename" DIR

where DIR is the directory name.  For this command to work, the "userdefined" and "basename" must be defined.  The sample config file (https://exiftool.org/config.html) defines the BaseName Composite tag, and shows you how to define your own user-defined EXIF tags.

- Phil
Title: Re: Writing Userdefined Tag with filename
Post by: ezeeckiel on April 15, 2013, 06:40:51 AM
Dear Phil,
Thanks for the quick answer,
Now I have some clues where to begin !
I'll let you know how things go
Olivier
Title: Re: Writing Userdefined Tag with filename
Post by: ezeeckiel on April 15, 2013, 10:40:04 AM
Dear Philip,

I've tried to figure out how to use substr but I'm stuck

here is the config file. I got the idea from an other post :
  BaseName => {
            Require => {
                0 => 'FileName',
            },
            # remove the extension from FileName
            ValueConv => 'my $name=$val[0]; $name=~s/\..*?$//; $name',
        },
BaseNameLast => {
Require => {
0 => 'BaseName',
      },
ValueConv => 'my $name=$val[0]; my $pos=index($name, "_")+1; $name=substr($name, $pos - $name)',
    },


My files are
aaaaa_xx.jpg
bbbbb_xx.jpg
cccccc_xxx.jpg   (sometimes more than 100 have the same name)

I would like to get the file name whitout the _xx or _xxx
does rsubstr work with exiftool ? I can't make it work either

cheer
sOli
Title: Re: Writing Userdefined Tag with filename
Post by: Phil Harvey on April 15, 2013, 10:52:10 AM
Try this:

ValueConv => 'my $name=$val[0]; $name=~s/_.*?$//; $name',

this removes everything from the first underline onwards.

- Phil
Title: Re: Writing Userdefined Tag with filename
Post by: ezeeckiel on April 15, 2013, 05:39:42 PM
Dear Philip,
You're the best.
Olivier
Title: Re: Writing Userdefined Tag with filename
Post by: Phil Harvey on April 15, 2013, 07:55:14 PM
Glad that worked.  I'm just posting back to note that I misspoke.  That expression will remove everything from the last underline onwards, not the first.  (In case there are more than one underlines.)

- Phil