Author Topic: Getting date / datetime from folder structure  (Read 181 times)

PowerGamert

  • Newbie
  • *
  • Posts: 3
Getting date / datetime from folder structure
« on: July 14, 2020, 04:27:19 PM »
I've been struggling with exporting my iCloud photos for days now.

Yes, i am able to export the photos. But, although they are neatly ordered by the correct in the iCloud, they loose that data after export. Only around 40% of the photos have usable meta data (like exif photo taken, or a correct creation date). It's really driving me insane that it isn't using the datetime that is stored in the iCloud library.

Ahyhow! The photos are exported in a directory tree which does have the correct date. So i'm hoping that i can use that in combination with exiftool to create a correct date.
For example:

I have a file called "IMG_2726" which is stored in the filepath "../2015/05/07/20150507-092514"

As you can see. The final folder holds all information that i need. I dont really care about the time, so if that makes it hard.. no problem. Just hoping that the correct date is a possibility.

Greetings and thanks!

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3948
Re: Getting date / datetime from folder structure
« Reply #1 on: July 14, 2020, 10:28:32 PM »
Just to be clear, the full filepath is something like?
../2015/05/07/20150507-092514/IMG_2726.jpg

EXIF time stamps require a time portion as well as a date.  And since it appears that the time is in the last part of the directory path, it would easier to just copy that.

The basic command would be along these lines (I'm assuming Mac, swap double/single quotes for Windows CMD)
exiftool '-DateTimeOriginal<${Directory;$_=(split "\/",$_)[-1]}' /path/to/files/

The split part splits the filepath into an array and takes the last entry as the value to copy into DateTimeOriginal.

Edit: Fixed quoting error
« Last Edit: July 15, 2020, 11:53:15 AM by StarGeek »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

PowerGamert

  • Newbie
  • *
  • Posts: 3
Re: Getting date / datetime from folder structure
« Reply #2 on: July 15, 2020, 04:44:13 AM »
Just to be clear, the full filepath is something like?
../2015/05/07/20150507-092514/IMG_2726.jpg

EXIF time stamps require a time portion as well as a date.  And since it appears that the time is in the last part of the directory path, it would easier to just copy that.

The basic command would be along these lines (I'm assuming Mac, swap double/single quotes for Windows CMD)
exiftool '-DateTimeOriginal<${Directory;$_=(split '\/',$_)[-1]}' /path/to/files/

The split part splits the filepath into an array and takes the last entry as the value to copy into DateTimeOriginal.

I'm at windows at the moment. So i indeed had to change out the quotes.

I added -r to all scan all subdirectories. After doing that the "time" part of the DateTimeOriginal holds the year. It doesn't really matter for me, but maybe you can shine some light on that.
Also i used -overwrite_original to get rid of al the _original files.

Thanks!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16878
    • ExifTool Home Page
Re: Getting date / datetime from folder structure
« Reply #3 on: July 15, 2020, 06:35:00 AM »
On Windows, your command should be:

exiftool "-DateTimeOriginal<${Directory;$_=(split '\/',$_)[-1]}" /path/to/files/

(the inner quotes should be single)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3948
Re: Getting date / datetime from folder structure
« Reply #4 on: July 15, 2020, 11:52:11 AM »
Oops, I did make a quoting mistake in my first post. Phil gives the proper command

I added -r to all scan all subdirectories. After doing that the "time" part of the DateTimeOriginal holds the year. It doesn't really matter for me, but maybe you can shine some light on that.

What is the full directory path on one of these files?

My command takes the last directory in the path, so if there are subdirectories below /2015/05/07/20150507-092514/, the results will be unexpected.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

PowerGamert

  • Newbie
  • *
  • Posts: 3
Re: Getting date / datetime from folder structure
« Reply #5 on: July 16, 2020, 04:42:23 AM »
The problem was
I've been struggling with exporting my iCloud photos for days now.

Yes, i am able to export the photos. But, although they are neatly ordered by the correct in the iCloud, they loose that data after export. Only around 40% of the photos have usable meta data (like exif photo taken, or a correct creation date). It's really driving me insane that it isn't using the datetime that is stored in the iCloud library.

Ahyhow! The photos are exported in a directory tree which does have the correct date. So i'm hoping that i can use that in combination with exiftool to create a correct date.
For example:

I have a file called "IMG_2726" which is stored in the filepath "../2015/05/07/20150507-092514"

As you can see. The final folder holds all information that i need. I dont really care about the time, so if that makes it hard.. no problem. Just hoping that the correct date is a possibility.

Greetings and thanks!

The problem disappeared after correcting the middle quotes back to single :)