Combining renaming files and moving to a new directory hierarchy

Started by Laurens, February 27, 2014, 03:19:09 PM

Previous topic - Next topic

Laurens

Hi,

It's the first time I use the tool to do some management of Pictures. I have Reconyx (camera) pictures that need to be renamed and put in a new folder structure. The desired structure: ./TriggerMode/Location/Year/Month/Day/Location_yyyymmd-hhmmss_Trigger_Number.JPG

The crux is probably that I want to use the CreateDate tag twice.

What I have at the moment working:
renaming
exiftool -config ./ExifTool_config -r -d %Y%m%d_%H%M%S '-FileName<${UserLabel}_${CreateDate}_$Trigger$Number.$FileExtension' ./test/
moving to new directory
exiftool -r -d %Y/%m/%d/%f.%%e '-FileName<$TriggerMode/$UserLabel/${CreateDate}' ./test/

Is there a way to do this in one line?


Little subquestion; I use a ExifTool_config file in the renaming because couldn't figure out how to only take the first character of a string directly.
e.g.
$Tigger is just the first character of $TriggerMode. So something like ${TriggerMode;m/(.)/} should do the trick, but it's creating directories like "Location_20131129_113300_Time Lapse;m" instead. (I'm running exiftool on linux, if that makes any difference)
Any suggestions?

Thank you,
Laurens

StarGeek

Quote from: Laurens on February 27, 2014, 03:19:09 PM
So something like ${TriggerMode;m/(.)/} should do the trick, but it's creating directories like "Location_20131129_113300_Time Lapse;m" instead. (I'm running exiftool on linux, if that makes any difference)

Try ${TriggerMode;m/(.)/;$_=$1} instead.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Hi Laurens,

Quote from: Laurens on February 27, 2014, 03:19:09 PM
renaming
exiftool -config ./ExifTool_config -r -d %Y%m%d_%H%M%S '-FileName<${UserLabel}_${CreateDate}_$Trigger$Number.$FileExtension' ./test/
moving to new directory
exiftool -r -d %Y/%m/%d/%f.%%e '-FileName<$TriggerMode/$UserLabel/${CreateDate}' ./test/

I would normally have suggested this for the second command: ... -d %Y/%m/%d '-Directory<$TriggerMode/$UserLabel/$CreateDate' ...

QuoteIs there a way to do this in one line?

If there weren't any tag names in between the date/time number in your path, this could be done in a single command because ExifTool allows you to set the file name and directory together by writing FileName with a full path specification:

exiftool -r -d %Y/%m/%d/%Y%m%d_%H%M%S '-filename<$triggermode/$userlabel/${createdate}_${userlabel}_$triggerNumber.%e' ./test/

But I had to change the ordering here so I can get all of the date/time items together for the format statement.

Too bad you can't insert tags into the -d format statement.  But that would mean double-interpolating the format string, which I think would be confusing and could yield unexpected results.

However, what you want to do is still possible, but a bit tricky:

exiftool -r -d %Y/%m/%d '-filename<${triggermode;m/(.)/;$_=$1}/$userlabel/$createdate/${userlabel}_${createdate#;tr/://d;tr/ /_/}_$triggernumber.%e' ./test/

For the CreateDate in the file name I use a '#' to start with the unformatted value, then add the necessary translations to get the format you want.  And I have also used StarGeek's method to take the first character of TriggerMode.

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

Laurens

Hi,

Thank you for the quick response.

It sounds logical not to insert other tags within one date format statement (although I tried to use two -d statements, in the hope that it would be applied consecutively). Putting the UserLabel after the date may be less perfect, but probably will do.

The single line solution looks good, but it's not working yet.
{triggermode;m/(.)/;$_=$1} gives me the following error: Warning: [minor] Tag '_' not defined - ./test/IMG_0009.JPG Warning: No writable tags set from ./test/IMG_0009.JPG

and exiftool -r -d %Y/%m/%d '-filename<$triggermode/$userlabel/$createdate/${userlabel}_${createdate#;tr/://d;tr/ /_/}.%e' ./test/ creates the following path and filename: ./Time Lapse/userlabel/2013/11/29/userlabel_2013:11:29 11:18:00;tr/:/d;tr/ /_/}.JPG
It looks like the directory part goes like it should, but then a directory is created "userlabel_2013:11:29 11:18:00;tr", so it looks like that the {} aren't interpreted and it takes the next / for a directory.

A workaround that I just thought of is to make the date directory part in the ExifTool_config so that I don't have to change the tags in the command line. Suggestions to make it work without the ExifTool_config file are welcome though, It would increase the share-ability.

Laurens

Phil Harvey

Hi Laurens,

It sounds like you have an old version of ExifTool.   You need version 9.30 or later to use this feature.

I just tried this command on an HC500 image.  It works for me after I removed $triggernumber from the FileName string, since there was no such tag as TriggerNumber in my image.

Creating a user-defined tag to do the date formatting is also a good possibility.  The file config file could look like this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDirectory => {
            Require => 'CreateDate',
            ValueConv => '$_=$val; s/ .*//; tr{:}{/}; $_',
        },
    },
);


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

Laurens

Hello Phil,

Feeling stupid now, I guess we learn. (So I didn't even have to fix the Reconyx makenote, because it was fixed in 9.31)

After the update it works like a charm. I did some more tweaking and ended up with the following
exiftool -r -d %Y/%m/%d '-filename<$triggermode/$userlabel/$createdate/${userlabel}_${createdate#;tr/://d;tr/ /_/}_${triggermode;s/(.)(.*\s)(.)(.*)/$1$3/}${sequence;s/(\d)(.*)/-$1/}-$eventnumber.%e' ./test/

Resulting in:
./Motion Detection/Location/2013/11/29/Location_20131129_111524_MD-1-1.JPG
./Time Lapse/Location/2013/11/29/Location_20131129_112700_TL-0-4.JPG

Thank you for this powerful tool and the help,

Laurens

Phil Harvey

Hi Laurens,

Nice.  Glad it works for you now.

I would suggest one small change:  -${sequence;s/ .*//} instead of ${sequence;s/(\d)(.*)/-$1/}

Otherwise you will have problems for sequences of 10 or more pictures (since you were only taking the first digit).

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

Laurens

Hi Phil,

I assumed not to have sequences more than 10, but one never knows, so good suggestion.

Thank you again,

Laurens

ps. I can't wait to unleash this line of code over +1 million pictures :-)