ExifTool Forum

ExifTool => Newbies => Topic started by: JWA on October 20, 2021, 03:33:29 PM

Title: Extract years?
Post by: JWA on October 20, 2021, 03:33:29 PM
Hello! I'm new here and just starting out with programming and using exiftool. I have a folder with many sub-folders containing roughly 3 million jpeg images. These images have been taken from 2013-2020. The problem here is that the file is too big when converting csv to excel, so I was wondering if there's a way to only extract say OriginalTimeDate from 2015 into a csv while ignoring the rest of the years? Or even a code for selected months of a year? The code I'm using now is: exiftool -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof.csv but it obviously isn't restricted to images from only the year 2015.

Thank you in advance!
Title: Re: Extract years?
Post by: StarGeek on October 20, 2021, 04:47:01 PM
Try
exiftool -if "$DateTimeOriginal  ge '2015' " -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof.csv

If you want a range of specific dates, you would use something like
exiftool -if "$DateTimeOriginal  ge '2015:02:01' and $DateTimeOriginal lt '2016:02:01' " -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof.csv
This would select files with a DateTimeOriginal value from 2015:02:01 00:00:00 until 2016:01:31 23:59:59.
Title: Re: Extract years?
Post by: JWA on October 20, 2021, 05:27:51 PM
Thank you, it scanned my directories but failed all files so 0 files were read. I'm on mac and changed the " to ' around the $ argument but it did not help. Is there another argument for mac users?
Title: Re: Extract years?
Post by: StarGeek on October 20, 2021, 05:45:03 PM
No, only the change of quotes would be needed.
exiftool -if '$DateTimeOriginal  ge "2015:02:01" and $DateTimeOriginal lt "2016:02:01" ' -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof.csv

Otherwise, check to make sure the files actually have a DateTimeOriginal
Title: Re: Extract years?
Post by: JWA on October 20, 2021, 06:13:14 PM
Yes sorry there was a sneaky double space:ing that I missed in the code, it worked at reading the files, but it still reads all files so it includes other years than the 2015 mentioned in the code. And yes the files have both a DateTimeOriginal and a CreateDate  :)

I tried the year suggestion:
exiftool -if '$DateTimeOriginal ge "2015" ' -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof.csv
and even tried changing the "2015" to just '2015' without any luck. So I also tried
exiftool -if '$DateTimeOriginal ge "2015:01:01" and $DateTimeOriginal lt "2015:12:31" ' -DateTimeOriginal /Dir/FilePath -ext jpg -r -csv >nameof1.csv and it worked!  ;D

I guess the command also needs to include month and day to work and that year alone isn't enough?
Title: Re: Extract years?
Post by: StarGeek on October 20, 2021, 07:32:18 PM
My mistake.  For some reason I read you post as wanting files from 2015 onward and nothing before that date.

Using something like
-if '$DateTimeOriginal gt "2015" and $DateTimeOriginal lt "2016" '
should work

Using 2015:12:31 would exclude all files that were on that date, as 2015:12:31 00:00:00 to 2015:12:31 23:59:59 are greater than just 2015:12:31.   Using lt 2016 will capture all files up to and including 2015:12:31 23:59:59.
Title: Re: Extract years?
Post by: JWA on October 21, 2021, 02:49:14 AM
Ooh, I see! No, worries, now I understand how the command line works and have more ways than one to sort out my images!

Thank you for your help!  ;D