Write csv reading only first and last file in a folder

Started by jbarnes, November 06, 2018, 08:46:54 PM

Previous topic - Next topic

jbarnes

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

StarGeek

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.
"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

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

jbarnes

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.