Can I do this via the command-line ?

Started by tmark, June 11, 2015, 08:55:10 PM

Previous topic - Next topic

tmark

I've got a mess of digital images and videos and am hoping to arrange them in folders named based on the year and month, and in files named by the date and time the image or video was captured.

I've read through the man page and the FAQ and I didn't see anything that corresponds to what I want to do.

I have a few rubs in my situation:

1) some file formats - specifically, videos - often don't have metadata *inside them* about the capture time and date.  So in cases where there is metadata inside the file about creation/capture time and date, I'd like to use that; otherwise I'd like to use filesystem metadata.

2) In many of my files, it seems that some programs have played havoc with the filesystem modification and creation times.  In some cases, the modification time has been touched so that it does not reflect when the file was captured; in other cases the creation time has been changed.  In all cases, I want to use the modification date and time that is earliest.

In short, I want to rename/ move files using the following rules:
- if the file contains metadata about the capture time, use that as the basis for rename/move
- otherwise, use the earliest of the filesystem creation and modification timestamps as the basis for rename/move

Can I do this with a command line invocation, or will I likely need to use the Perl library to capture this logic ?

Thanks - this looks an amazing piece of work that will save me countless hours from writing something ground up.

terry

Phil Harvey

Hi Terry,

The only tricky part here is deciding between FileModifyDate and FileCreateDate (assuming you are on Windows).  I have added Example 12 to the File Renaming page to explain the basic concept.  Please let me know if this makes sense.

The tricky part may be handled in at least 3 different ways:

1) A Composite tag based on FileModifyDate and FileCreateDate that returns the earlier one.

2) Using 2 commands and a -if condition to use the earlier date.

3) Using and advanced formatting expression and accessing API functions.

Here I will use 3 because it is most efficient and doesn't require creation of a config file (although it is probably the most difficult to understand).  For method 3, the command could be:

exiftool -d %Y/%m "-directory<${filecreatedate;my $m=$self->GetValue('FileModifyDate'); $m lt $_ ? $m : $_}" "-directory<createdate" "-directory<datetimeoriginal" .

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

tmark

Wow.  I am going to need to dig into the API to understand what the example posted here is doing, especially what the value of $_ is here ( I know how it is typically used in Perl, but not sure of the surrounding context in which it is used here).

But the example 12 you added is simply stupefying.  I can't believe the conciseness in how it does what it does.

And the notion that my full use case could also be concisely captured in one-liner - well, my jaw is still on the floor.

May I suggest that examples of how to handle your first and second approaches might be very instructive for users looking at even more complicated cases than mine ?

Kudos, Phil, kudos.  And thank you.


StarGeek

Quote from: tmark on June 12, 2015, 09:37:31 PM
Wow.  I am going to need to dig into the API to understand what the example posted here is doing, especially what the value of $_ is here ( I know how it is typically used in Perl, but not sure of the surrounding context in which it is used here).

ExifTool is written in Perl, and it's used the same way.  Basically, everything between the braces except the tag name is a line of perl code and $_ is the data from the tag.
* 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).

tmark

So, I was finally able to try this.  On Mac OS X, I get:

tmark$ exiftool -d %Y/%m "-directory<${filecreatedate;my $m=$self->GetValue('FileModifyDate'); $m lt $_ ? $m : $_}" "-directory<createdate" "-directory<datetimeoriginal"  .

-bash: -directory<${filecreatedate;my $m=$self->GetValue('FileModifyDate'); $m lt $_ ? $m : $_}: bad substitution


It seems that the problem lies somewhere in the first quoted argument:


tmark$ exiftool -d %Y/%m "-directory<${filecreatedate;my $m=$self->GetValue('FileModifyDate'); $m lt $_ ? $m : $_}"  .
-bash: -directory<${filecreatedate;my $m=$self->GetValue('FileModifyDate'); $m lt $_ ? $m : $_}: bad substitution
strummyair:exiftool tmark$


I'm not sure where to begin here ?

StarGeek


From Phil's .sig
On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).
* 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).