CAMERA MODEL AS PART OF THE FILENAME DURING RENAMING REQUIRED

Started by ULSWK, July 13, 2011, 04:21:44 AM

Previous topic - Next topic

ULSWK

Hi,
I'm new to the exiftool, but i have nearly - but only nearly - reached what I need.

Currently I use the following code in my batchfile:
dir %TargetPath%\TEMP1\*.* /A:-D /B /S  >%TargetPath%\TEMP3\TEMPFILELIST.TXT

For /f %%a in (%TargetPath%\TEMP3\TEMPFILELIST.TXT) do %Exiftool%\exiftool.EXE -r -d %%Y%%m%%d_CAMERAMODELL_%%%%-4f%%%%-c.%%%%e "-FileName<createdate" %%a

What it does:
The first statement collects all files below ..\TEMP1 and writes their filenames into  a textfile in ..\TEMP3

The interesting code is the for statement.
Using this, I can rename all files one by one.

The result of the renaming looks like this:
YYYYMMDD_CAMERAMODELL_####.NEF where #### is the numeric part of the original filename.
You can see the Text "_CAMERAMODELL_" in the sting.

The goal is to replace this with a short code which represents the used camera.
Eg. I use a NIKON D200. Until now I manually use the code "_N2_" for this camera.
So, a fine filename should look like this: 20110712_N2_1234.NEF

Is it possible to implement something similar with the EXIFTOOL ??

Ulrich

Phil Harvey

Hi Ulrich

No batch file is needed.

Use this exiftool command:

exiftool -r -d %Y%m%d "-FileName<${createdate}_${myModel}_%-4f%-c.%e" DIR

where DIR is the name of the directory containing the images.

Using this config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyModel => {
            Require => 'Model',
            # remove characters that are illegal in Windows file names
            ValueConv => '$val =~ tr{\\\/?*:|"<>}{}d; $val',
        },
    },
);
1;  #end


See the config file documentation for instructions on how to activate the config file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ULSWK

Hi Phil,
thank's for your very quick response !!

It sounds great, but I didn't understood it fully.
Can you please help again ?

I 'filled' the CFG File with this:
------------------------------------------------------------------------------
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyModel => {
            NIKON D200 => 'N2',
            # remove characters that are illegal in Windows file names
            ValueConv => '$val =~ tr{\\\/?*:|"<>}{}d; $val',
        },
    },
);
1;  #end
------------------------------------------------------------------------------

and then I changed the exiftool line in the batch to the following:

%Exiftool%\exiftool.exe -config %Exiftool%\EXIF_CONFIG_FILE_US.CFG -r -d %%Y%%m%%d "-FileName<${createdate}_${myModel}_%%%%-4f%%%%-c.%%%%e" %TargetPath%\TEMP1

%Exiftool% is the path with EXIFTOOL
%TargetPath%\TEMP1 is the path with all the images
%-Chars are duplicated for useage in a batch file
%Exiftool%\EXIF_CONFIG_FILE_US.CFG is the path and name of the config file from above.

The result is a syntax error in line 4 near NIKON D200.
Can you tell me that my mistake is ?
I didn't understand where I have to reference to the 'model' EXIF-TAG.
I think the 'MyModel' musn't be changed because it is the link to the exiftool command line.

Greetings from a very rainy germany
Ulrich

Phil Harvey

Your config file should be exactly like mine.  I don't know what you are trying to do with the "NIKON D200" line.

Also, you have 4 '%' characters where you should only have 2 for %%f and %%f.  You only need 4 if it is the argument of -d, but it isn't.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ULSWK

Obviously I didn't understand the code structure well enough...
I changed I to the original structure form you and nearly got what I am looking for.

E.g. the resulting filename now looks like 20110709_NIKON D200_3353.NEF, but should look like
20110709_N2_3353.NEF, because this is much smaller, and the information for me is the same.

I understood your first answer that there is a possibility to substitute a statement with another. Is that correct ?
Is it possible to implement a substitution list for my four possible camera models with user defined abbreviations ?

Phil Harvey

Sure, you can add any Perl code you want in the ValueConv statement.  Try this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyModel => {
            Require => 'Model',
            # do translations and substitutions
            ValueConv => q{
                $val =~ tr{\\\/?*:|"<>}{}d;
                $val =~ s/NIKON D200\b/N2/i;
                return $val;
            },
        },
    },
);
1;  #end


Here I have done a case-insensitive (the trailing "i" makes it case insensitive) substitution of "NIKON D200" for "N2".  The "\b" matches at a word boundary, which will prevent this from matching something like "NIKON D2000".

And you can add extra lines for any additional substitutions that you want.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ULSWK

Hi Phil,
that is pretty cool !
Thank's for your advice. It works really well.

Ulrich