ExifTool Forum

ExifTool => Newbies => Topic started by: PowerGamert on July 14, 2020, 04:27:19 PM

Title: Getting date / datetime from folder structure
Post by: PowerGamert 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!
Title: Re: Getting date / datetime from folder structure
Post by: StarGeek 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
Title: Re: Getting date / datetime from folder structure
Post by: PowerGamert on July 15, 2020, 04:44:13 AM
Quote from: StarGeek 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.

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!
Title: Re: Getting date / datetime from folder structure
Post by: Phil Harvey 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
Title: Re: Getting date / datetime from folder structure
Post by: StarGeek on July 15, 2020, 11:52:11 AM
Oops, I did make a quoting mistake in my first post. Phil gives the proper command

Quote from: PowerGamert on July 15, 2020, 04:44:13 AM
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.
Title: Re: Getting date / datetime from folder structure
Post by: PowerGamert on July 16, 2020, 04:42:23 AM
The problem was
Quote from: PowerGamert 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!

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