ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: jbarnes on November 06, 2018, 08:46:54 PM

Title: Write csv reading only first and last file in a folder
Post by: jbarnes on November 06, 2018, 08:46:54 PM
Hi exiftoolers, I'm trying to streamline my workflow for my camera trap data, and hoping someone might have some code to share for what I hope is an easy fix.

I need to write a csv with the DateTimeOriginal tag of just the first and last photos in a given folder so that I know the time period during which each camera was active. I've been going about this the long-winded way of using:

exiftool -csv -DateTimeOriginal -r -ext jpg "C:/directory/name/here" > name.csv

... but as I have ~150,000 photos per directory, this can take quite some time and writes an enormous csv file that I then need to systematically work through and keep ONLY the first and last records. Is there a way I can run similar code but write a csv that automatically omits all the intervening photographs?

Thanks in advance!
Jarrad
Title: Re: Write csv reading only first and last file in a folder
Post by: StarGeek on November 06, 2018, 09:28:49 PM
I can't think of a way to only return the oldest and newest files out of a directory, but with some googling, I made an (mostly untested) batch file that might do it
FOR /F "delims=" %%I IN ('DIR *.jpg /O:-D /B') DO set old=%%I
FOR /F "delims=" %%I IN ('DIR *.jpg /O:D /B') DO set new=%%I
exiftool -csv -Fileorder DateTimeOriginal -DateTimeOriginal -ext jpg %old% %new% > name.csv


This will grab the oldest and newest based upon FileModifyDate (I think).  Though this would be a problem if the FileModifyDate wasn't the same order as DateTimeOriginal.  If the names were alphabetically in order, you could switch /O:-D and /O:D to /O:-N and /O:N.
Title: Re: Write csv reading only first and last file in a folder
Post by: Phil Harvey on November 07, 2018, 07:09:48 AM
Hi Jarrad,

I can think of a way to do this on Mac/Linux which would pipe the -csv output of ExifTool through 'sort' to sort by DateTimeOriginal, then 'sed' to return only the first and last entries.  But I don't know how to do this in Windows.

This doesn't solve the speed problem though, since all files must be processed to extract DateTimeOriginal.

- Phil
Title: Re: Write csv reading only first and last file in a folder
Post by: jbarnes on November 08, 2018, 10:29:14 PM
Thanks StarGeek and Phil. I realised I'd been thinking about it all wrong, especially with the speed issue, and it's much easier (ready, less streamlined but faster) to just copy the first and last files of each folder into a new directory and work from that, which skips out all of the processing of those intervening files. Thanks.