preserve the current subdirectory name in exiftool operation

Started by kngharv, June 04, 2021, 08:46:30 PM

Previous topic - Next topic

kngharv


Since I've been taking photos for a long time, predates DSLR, I have long organized photo by date.  Typically, I create a subdirectory which contains the date and a description of the event, such as

./20200721_cometC2020F3_neowise

where first 8 digit is always year, month, and day

I want to use exiftool to categorize photos in each of subdirectory and create a subdirectory inside it based upon
1. photo that has GPS info
2. photo has date but no GPS
3. photo doesn't have any exif info at all

so, idealy, the result will be

~/photo/20200721_cometC2020F3_neowise/geotag
~/20200721_cometC2020F3_neowise/timeStamp
~/20200721_cometC2020F3_neowise/noEXIF

and depend upon where rather the photo has appropriate info, the image file will move to appropriate subdirectory INSIDE the original subdirectory

I know about exiftool -directory

I also know about -filepath variable, which will return the filename with full path
/home/user/photo/20200721_cometC2020F3_neowise/DSC_3445.JPG

What I don't know is how to preserve  the name of the subdirectory immediate before the file name.

i need to do something like this:
exiftool -directory=$subDirectoryName_of_the_JPG_file/geoTag -if '($GPSDateStamp)' .

how to do that with advanced formatting? 

thanks in advance

Harv

Phil Harvey

Hi Harv,

Use %d to represent the original directory of the file.  So I think you want this:

exiftool -directory=%d/geoTag -if '($GPSDateStamp)' .

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

Luuk2005

Greetings Harv, Im also discovered a way to conduct some of the subdirectory logic without using many -if statements.
To replace many -if's, Im often use something like... -directory'<${Directory}/Text and ${ConditionalTagName;s/.*//}'
This because if $ConditionalTagName does not exist, then exiftool stays prejudice against the Text and part.

So for your sub-directories, the command might look like...
exiftool -m -directory=%d/NoEXIF -directory'<${Directory}/timeStamp${DateTimeOriginal;s/.*//}' -directory'<${Directory}/geotag${GPSDateStamp;s/.*//}' DIR

So at first, the exiftool decides for "NoEXIF" to be the default subdirectory name.
But then, if finding $DateTimeOriginal, will choose timeStamp for the subdirectory.
But then, if finding $GPSDateStamp, will instead choose geotag for the subdirectory.

Of course -directory=%d/NoEXIF is not really studying the file (like with an -if), to see if theres no exif data.
Its just assuming that if $DateTimeOriginal and $GPSDateStamp dont exist, then NoEXIF should be the subdirectory name.
So if you're already using many -if's to check many $exif-dates besides $DateTimeOriginal, you could insert something before geotag like...

-directory'<${Directory}/timeStamp${ExifDateTag2;s/.*//}' -directory'<${Directory}/timeStamp${ExifDateTag3;s/.*//}' ...
The s/.*// is just destroying all the DateTag values, but I like the way this does make the whole -option to be conditional.
Lol, so Im hoping this never gets changed with an update, like when we are not using any parts of the tag value (please).
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7