Extract part of string

Started by mulcamd, January 16, 2011, 02:43:55 PM

Previous topic - Next topic

mulcamd

Hi,

I would like to rename and move my Canon raw files in the way of:
D:\YYYY\MM\YYYY_MM_DD\<Initials>_YYYYMMDD_filenumber.extension: like
D:\2011\01\15\PHX_20110115_9776.CR2

I found the $filenumber tag of Canon. This says 297-9776. I would like to have only the last 4 digits.

I tried several but could not get the right result. Especially extracting the last 4 digits. I also could not find how to extract part of a string tag result

Phil Harvey

FAQ number 19 may answer some of your questions (but after reading this you'll likely be back with others...).

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

mulcamd

Hi Phil,

I tried the following, but do not get the right result.
The result I get is: DAH_20100903_${MyFileNumber}.CR2
This should be DAH_20100903_8345.CR2

I used the following command in a Windows batch file:
exiftool "-config ExifTool_config" "-filename<Createdate" -d "D:/Foto's/Test/%%Y%%m%%d/DAH_%%Y%%m%%d_${MyFileNumber}.%%%%e" "E:\Foto's\2010\09\2010_09_03\*.CR2"

The config file is named: .ExifTool_config
MyFileNumber should result the last 4 digits of 300-8345

It contains:

%Image::ExifTool::UserDefined = (
   'Image::ExifTool::Composite' => {
       MyFileNumber => {
           Require => 'FileNumber',
           ValueConv => '$val =~/(\d\d\d\d)$/; $val',
       },
   },
);
1; # end

In the makernotes filenumber is like: 300-8345

Whats do i wrong?

Phil Harvey

Very good.  You nearly got it.  Just one little change:

ValueConv => '$val =~/(\d\d\d\d)$/; $1',

The $1 represents the 1st expression in brackets (in this case, the 4 digits).

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