Photos Date Sort Exif Data

This is more of my findings than a support question… I’m hoping this can help other people…

im using nextcloud 19
client IOS on iPhone and iPad

When adding images to the nextcloud environment everything is dated and sorted by date correctly if it is a brand new picture taken at that time.

When things can get funky is when you’re trying to manipulate your collection of images. every time you copy a file from one disk to another the file modification information is updated. if you edit a file the file modification is updated. nextcloud and every other tool out there uses this file modification date to show the files sorted by modification date not create date. you don’t see this in IOS because when you edit an image it keeps the original image intact. in fact you can always revert to the original image on IOS.

the problems come when trying to correct this. simply updating the exif file modification time doesn’t completely fix the issue.
depending on the device the image was created on and the type of encoding some exif data may not always be present.

some of my files did not contain an exif original date so when copied to another drive the file modified date was updated moving the files to the most current date. frustrating

for files that did not have and exif date I was lucky that the original file was saved in a date format like YYYY-MM-DD_HH-MM-SS.png

Here is the process I used to correct my images

im using macOS so you may need to translate this to your OS of choice.

Tools: exiftool command line. this one tool can do it all but I find it easier to do the file rename with the gui tool ExifRenamer ExifRenamer gui

I used ExifRenamer. This tool takes the file and renames it to YYYY-MM-DD_HH-MM-SS.
I create a new folder style with the format of %Y%M

it does not update the file modified date to the correct date in batch renaming. so I do another step.

at this point all files that have a exif readable date are renamed.

Use the exiftool to set the file modify date to the file name date. keep in mind the file name must contain a 4 digit year. the ExifRenamer tool will do that for you.

exiftool -ee -r “-FileModifyDate<filename” {pathtophotots}*
-ee Extract information from embedded files
-r Recursively process subdirectories

at this point all of your files that were readable exif are renamed and the file modification date is corrected back to the create date.

I run the exiftool one more time to make sure Ive captured all variation of file issues.
exiftool -ee -r “-FileModifyDate<CreateDate” {pathtophotots}*

if there was a file that could not be renamed and it also has a create date this will correct the file modify date.

if your files are already on nextcloud filesystem your good to go to files:scan steps

if your files are in a different folder but on the same dataset/diskset. you can simply move them into the Photos folder of the user you want them in.

if your files are on a external disk you can mount the disk and copy them using cp -p the -p preserves times stamps.

once the files are in place this is the gotcha and I’m not sure if this is a bug or just the way it works.

if you can already see your files in your IOS app incorrectly date sorted you must move the folder out of the data path and perform a files:scan. when you check the IOS devices you should see no Photos. once the files:scan is complete move the Photos back into the Photos folder and perform another files:scan. when moving your files around on this step be sure to use cp -p or mv on the same disk so that time stamps are kept.

im not sure why files:scan does not update the info with the new date but I assume its because it thinks its already in the database so it skips that file info update.

your images should now show up in the correct dates.

sudo -u www php occ files:scan user or --all

one thing to keep in mind is when you move your photos out of the data directory any shares you have will get removed. you will need to put them back when you’re done.