Author Topic: %4f formatting for Filerename action  (Read 6280 times)


  • Newbie
  • *
  • Posts: 2
%4f formatting for Filerename action
« on: January 02, 2011, 09:12:10 AM »
Hello and a happy new year 2011 to all!

I have a small problem and can't find a solution. Maybe someone has got a short help for me?

i'd like to rename my picture with DateTimeOriginal and also an unique id. i would like to use the field shuttercount.
So i use the command "exiftool '-filename<${datetimeoriginal}_${shuttercount}.%e' -d %Y%m%d dir"
this is working fine. but now my 2 question:
The file is renamed in 20091231_5055.JPG, but i would like to have the shuttercount always in 8 digits, for example 20091231_00005055.JPG or 20091231_00055555.JPG.
Is it possible to do this like printf with "%08d"?

And then a 2nd Question:
if the field shuttercount is not present in the exif data, also i would like to rename the file like the schema above. The shuttercount then should 00000000, for example 20091231_00000000.JPG.

the goal is to have a possibiltiy to copy different storage locations to one base location. if the filename is present the file (picture) exists and there is no need to copy it again. Without unique id i have problem if more than one picture was created in the same second... (My old camera without shuttercount field did not have this function so there is no problem).

Anybody any idea? thank's!

Greetings Dirk

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: %4f formatting for Filerename action
« Reply #1 on: January 02, 2011, 12:34:43 PM »
Hi Dirk,

You can do both of these with a user-defined tag:

Code: [Select]
%Image::ExifTool::UserDefined = (
    # Composite tags are added to the Composite table:
    'Image::ExifTool::Composite' => {
        MyShutterCount => {
            Desire  => { 0 => 'ShutterCount' },
            Require => { 1 => 'FileName' },
            ValueConv => 'sprintf("%.8d", $val || 0)',
1;  #end

Notice that I add a Require'd tag which always exists so that this Composite tag will be generated for all files.

See the sample config file for instructions on how to activate this configuration file.

With this installed, you can use $myShutterCount to get what you want.

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


  • Newbie
  • *
  • Posts: 2
Re: %4f formatting for Filerename action
« Reply #2 on: January 04, 2011, 01:35:20 PM »
Hi Phil,

thank you for your quick response.

Your example did exactly what i want - the user-defined tag function is really great.

Thank you very much for the great tool and great job!