Filenumbering with leading Zero?

Started by Fluschly, January 01, 2013, 08:31:35 AM

Previous topic - Next topic

Fluschly

Hello,

I am using exiftool although for renaming the filenames. The original filenames are like DSC_xxxx.jpg. Currently I use following command:


exiftool "-FileModifyDate<MyDateTime" -ext jpg "-FileName<${DateTimeOriginal}_${MyModel}_%%-4f.jpg" -d %%Y%%m%%d_%%H%%M%%S -overwrite_original %1


.ExifTool_config is like that:



%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDateTime => {
            Require => {
               0 => 'DateTimeOriginal',
            },
            ValueConv => '$val[0]',
        },
        MyYear => {
            Require => {
                0 => 'DateTimeOriginal',
            },
            ValueConv => '$val[0] =~ /(\d+)/; $1',
        },
        MyModel => {
             Require => {
                 0 => 'EXIF:Model',
             },
             ValueConv => '$val[0]',
             PrintConv => {
                'NIKON D70' => D70,
                'NIKON D90' => D90,
                'NIKON D7000' => D7000,
                'COOLPIX L21' => L21,
                'HP Photosmart R740' => R740,
             },
         },
    },
);


Now I need to extend to 5 digits and would like to have a leading 0 if the number is less than 10000:
DSC_7898.jpg --> DSC_07898.jpg

At the moment I can only do it manually with

... ${MyModel}_0%%-4f.jpg


Any idea to do it automatically?

Thanks and regards,
Juergen.

Phil Harvey

Hi Juergen,

I don't understand.  To do this automatically you need a 5-digit number to start with.  Where does this number come from?

- 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 ($).

Fluschly

Hi Phil,

sorry I should provide more details.
My camera uses a counter which goes from 0001 to 9999. If I take another photo the counter will restart with 0001, but I would like to have a 10000. For a good numbering I would need 09999 and then 10000, because then the files are displayed ascending and correctly. Otherwise 10000 comes before 9999.
For this I would like to have a leading zero in the filename.

In the meantime I tried to calculate the number with the help of ShutterCount in .ExifTool_config:


        MyShutterCount => {
          Require => 'ShutterCount',
            ValueConv => '($val - 12500)',   # my current offset
        },


and


exiftool "-FileModifyDate<MyDateTime" -ext jpg "-FileName<${DateTimeOriginal}_${MyModel}_${MyShutterCount}.jpg" -d %%Y%%m%%d_%%H%%M%%S -overwrite_original %1


But this is worse, because I only get the calculated number, e.g. 12600 - 12500 = 100 and the digits of MyShutterCount are only 3.

Regards,
Juergen.

Phil Harvey

Hi Juergen,

OK, if ShutterCount works, you can do something like this:

        MyShutterCount => {
            Require => 'ShutterCount',
            ValueConv => '($val - 12500)',   # my current offset
            PrintConv => 'sprintf("%.5d", $val)',
        },


Here I have added a print conversion to format the value as 5 digits.

- 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 ($).

Fluschly

Hi Phil,

thanks for the help. It works fine.
Would there be a possiblity without ShutterCount option? Maybe to do something like if number <= 9999 then put leading '0' before?

Regards,
Juergen.

Phil Harvey

The only points where you can insert logic like this are in the -if statement (but this would require 2 commands), or in a user-defined Composite tag.  In the Composite tag, you could do this:

    ValueConv => '$val <= 9999 ? "0$val" : $val',

To do what you describe.

- 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 ($).

Fluschly

Thanks a lot for your information. I will try and see what fits best.

Regards,
Juergen.