How to combine -Directory and -FileName

Started by J4c06r1nw1s, August 28, 2021, 11:01:03 AM

Previous topic - Next topic

J4c06r1nw1s

I want to achieve this in 1 step as below.
/volume/media/NIKON_D90/2021/08/28/NIKON__D90_2021-08-28_14.34.05__1234.DNG

For example the FileNames are like _DSC1234.DNG

This is what I have already discovered:

perl ~/Image-ExifTool-12.29/exiftool \
    -if '$Model eq qq{NIKON D90}' \
    -if '$MegaPixels >= 10' \
    -o . \
    '-Directory</volume1/sorted/${Model;s/ /_/g}/${CreateDate}' \
    -d %Y/%m/%d \
    -r '/volume1/import'

perl ~/Image-ExifTool-12.29/exiftool \
    -if '$Model eq qq{NIKON D90}' \
    -if '$MegaPixels >= 10' \
    '-FileName<${Model;s/ /_/g}__${CreateDate}__${FileNumber}.%e' \
    -d %Y-%m-%d_%H.%M.%S \
    -r '/volume1/sorted/NIKON_D90'


This works, but shouldn't this also be possible in 1 step instead of 2 steps?
I suspect this will take twice as long and I have 14 TB of files that I want to reorder and rename. These files are from different camera makes and models and taken in recent years.

And why does .%%e not work but .%e does?
'-FileName<${Model;s/ /_/g}__${CreateDate}__${FileNumber}.%%e'
NIKON__D90_2021-08-28_14.34.05__1234.%DNG
'-FileName<${Model;s/ /_/g}__${CreateDate}__${FileNumber}.%e'
NIKON__D90_2021-08-28_14.34.05__1234.DNG
Using ExifTool v12.37 on Linux

Phil Harvey

Try this:

perl ~/Image-ExifTool-12.29/exiftool \
    -if '$Model eq qq{NIKON D90}' \
    -if '$MegaPixels >= 10' \
    -o . \
    '-Directory</volume1/sorted/${Model;s/ /_/g}/${CreateDate#;DateFmt("%Y/%m/%d")}/${Model;s/ /_/g}__${CreateDate}__${FileNumber}.%e' \
    -d %Y-%m-%d_%H.%M.%S \
    -r '/volume1/import'


You only need to double the "%" character to pass it through the -d option.  So %e should only have one % because is isn't part of the -d format string.

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

StarGeek

You can include the directory path when writing to the Filename pseudo tag.  The only problem is that you have two different -d (-dateFormat) option format strings.

There are two ways to deal with this, either include all parts of the path in the date string, which will not work in this case as you have other tags in between the two date tags.  The other option is to use the DateFmt helper function.

So try this (I have not tested this, so it may require some tweaking)
-d %Y-%m-%d_%H.%M.%S '-FileName</volume1/sorted/${Model;s/ /_/g}/${CreateDate#;DateFmt("%Y/%m/%d")}/${Model;s/ /_/g}__${CreateDate}__${FileNumber}.%e'

Quote from: J4c06r1nw1s on August 28, 2021, 11:01:03 AM
And why does .%%e not work but .%e does?

Because the extension token is %e, not %%e.  See the details under the -w (-TextOut) option.  The part you're confusing is the fact that if %e (or other filepath tokens) are included in a -d date format string, then the percent sign is doubled there.  See Renaming Examples.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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

StarGeek

Heh, actually, I had it all typed up and the feral cat I'm trying to tame came all the way into my house begging for cat treats.  So, sorry, the kitty has higher priority :D

Darn it, Amazon isn't letting me share the picture.

Edit: Cat Tax
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

I understand.  A hungry kitty requires attention. :)

Edit:  Cute kitty.
...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 ($).

J4c06r1nw1s

Phil Harvey and StarGeek thank you so much. And answered so quickly. I've been working on it for days. Couldn't find this among all Google search results.

Is there a better description for the Subject? So that it is easy for others to look up? I've never been so good at a good Subject description.
Using ExifTool v12.37 on Linux

StarGeek

Quote from: J4c06r1nw1s on August 28, 2021, 11:58:45 AMIs there a better description for the Subject? So that it is easy for others to look up? I've never been so good at a good Subject description.

Not really.  While this subject has been covered before, unless you know exactly what to look for, it's hard for someone who hasn't had the problem to search for.  Add in the fact that Google searches the whole web by default and you get a lot of old, outdated, and incorrect random blog posts.

These forums are the best place for good information and it helps if you add site:exiftool.org to any search so as to limit the output to just this site.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype