Another newbie - setting date taken from folder name

Started by spinal, April 20, 2018, 02:30:38 PM

Previous topic - Next topic

spinal

Hello,
so I'm new here, and was hoping someone can point me in the right direction.

Two questions:
1. How do the regex's and replacements work? I had a look through the FAQ, but am still struggling. Would like to convert  the first four characters of the directory into the year, then skip one, then 2 characters into month and so on...
2. What am I doing wrong with the "manual" approach below?

I scanned "a few" family photos (30,000)... and have them divided into folders that include the date the pictures were taken. I'm now uploading to amazon images, but they all come up as "no date" (makes sense).
(if it makes a difference, most are TIF, but some are jpg - and I'm on osx).

Anyhow - let me continue my thought process...

My directory structure is thus:
/PictureDepot/YYYY/YYY-MM-DD - YYYY-MM-DD Location Description"
e.g.
/PictureDepot/1971/1971-01-27-1971-02-01 Rio Work
(the dates are start and end date - but as long as I can get the start date into the date taken, I will be a LOT happier)

So what I tried as a first step is:
from the 1971 directory:
exiftool 'alldates<19710127 000000' 1971-01-27-1971-02-01\ Rio/
but this doesn't work... so I'm clearly doing something wrong.

Any help or ideas appreciated, even if it's pointing me in the direction of a section of the faq...

(p.s. also played a bit... created a folder called test, with only the 1971 directory inside (e.g. /test/1971/1971-01-...etc)
exiftool 'alldates<19710127000000' -r test/
exiftool 'alldates<"19710127000000"' -r test/
exiftool 'alldates<19710127 000000' -r test/

but none of these seem to work...
M.

spinal

Right, so doing some more testing...

centralcommand:1971-01-27-1971-02-01 Rio ladmin$ exiftool -a -G1 -s Rio-02.tif
[ExifTool]      ExifToolVersion                 : 10.93
[System]        FileName                        : Rio-02.tif
[System]        Directory                       : .
[System]        FileSize                        : 6.1 MB
[System]        FileModifyDate                  : 2017:12:08 10:49:30+00:00
[System]        FileAccessDate                  : 2018:04:20 19:49:49+01:00
[System]        FileInodeChangeDate             : 2018:04:20 18:53:53+01:00
[System]        FilePermissions                 : rwxr-xr-x
[File]          FileType                        : TIFF
[File]          FileTypeExtension               : tif
[File]          MIMEType                        : image/tiff
[File]          ExifByteOrder                   : Big-endian (Motorola, MM)
[IFD0]          ImageWidth                      : 1748
[IFD0]          ImageHeight                     : 1215
[IFD0]          BitsPerSample                   : 8 8 8
[IFD0]          Compression                     : Uncompressed
[IFD0]          PhotometricInterpretation       : RGB
[IFD0]          StripOffsets                    : 8
[IFD0]          Orientation                     : Horizontal (normal)
[IFD0]          SamplesPerPixel                 : 3
[IFD0]          StripByteCounts                 : 6371460
[IFD0]          XResolution                     : 300
[IFD0]          YResolution                     : 300
[IFD0]          PlanarConfiguration             : Chunky
[Composite]     ImageSize                       : 1748x1215
[Composite]     Megapixels                      : 2.1


That the file I've been playing with - and there's no date/time set from 1971 (or anything that far back...) from the previous commands... hmmm

EDIT:
I'm an idiot. Forgot the '-' sign before alldates... also, instead of < I used = and that works... guessing it's a mac thing,...

exiftool '-alldates=1971-01-27 00:00:00' 1971-01-27-1971-02-01\ Rio/
works fine... now to figure out the regex to extract the date from the directory :)

m .


Next edit, found the directory option... so
xiftool '-alldates=${directory} 00:00:00' -r 1971-01-27-1971-02-01\ Rio/
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in IFD0:ModifyDate (PrintConvInv)
Nothing to do.


(I'm hoping that my learning and posting as I learn helps someone... and maybe someone can help me :p)

StarGeek

Quote from: spinal on April 20, 2018, 02:52:52 PM
instead of < I used = and that works... guessing it's a mac thing

This would be common mistake 5c.  There is a difference between the usage of the equal sign = and the Less/Greater Than signs </>.  The Greater/Less Than signs are used to copy one tag to another.  The Equal sign is used to assign a static value.

Additionally, you'll want to read FAQ #5.  Due to your formatting of the directory name, the "00:00:00" part will never be seen and the time will be set for 19:71:02, which is the reason you get the invalid date/time.

To extract the right numbers from the directory, you could use
'-alldates<${directory;s/.*(\d{4}-\d\d-\d\d).*/$1/} 00:00:00'

This will look for the first pattern of 4DigitsDash2DigitsDash2Digits and remove everything else before and after in the directory name.  I'm suggesting this pattern so in case you want to start at a directory above this one and use the -r (recurse) option, it will also remove the Year part of the parent directory you mention (the first 1971 in /PictureDepot/1971/1971-01-27-1971-02-01 Rio Work).  I also don't bother removing the dashes in the above because, as mentioned in FAQ 5, it isn't needed as exiftool will ignore them.

Regex isn't really covered in the exiftool docs as it is a very complex subject by itself.  I always suggest reading Regular-expressions.info to learn about it but there are plenty of other sites as well.  Also, Regex101.com is a useful site to test out regex expressions, though, again, there are other similar sites.
* 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).

spinal

Thank you very much, that's most helpful!

d is digit (reading up, useful site, thanks!)

Here's a "spanner" that messes things up. In some cases, the folders have xx (I.e. no idea as to precise dates), so it now ignored the xx and takes the

Picture Depot ladmin$ exiftool -a -G1 -s 1984/1984-12-xx\ -\ 1985-03-xx\ Gambia\ Dicembre\ Marzo\ 1985\ \(1\)/DakaGambia.00475.jpg
[ExifIFD]       DateTimeOriginal                : 1984:19:84 12:19:85
[ExifIFD]       CreateDate                      : 1984:19:84 12:19:85


Short of renaming all the directories with xx to 00 or 01, any ideas? Is there a man page I can read up on how it strips the directory contents?

EDIT: ignore that, was being thick. Ended up renaming all the directories, was faster (grep). One thing, I noted that using 00 for an unknown day doesn't work. So a date of 2001-05-00 works in exiftool, but then amazon photos still shows unknown date.

I now need to work out how to deal with with the regex you've helpfully posted :) Reason being is that I have a few embedded folders (e.g.:
/1971/1971-01-27-1971-02-01 Rio Work/Restored
) which the command above doesn't capture. I'm guessign s/. uses only the current directory name and not hte full  path from root?