Is there an API to get the next increment of an image when?

When uploading images from your phone, the filename is changed to Y-m-d hh-mm-ss $(increment number)

Im planning of migrating a lot of images from MacOS Images app to an Nextcloud container, and I want to keep the filename structure, so is there a way of somehow fetching the last - or next increment of image?

And no, its not possible to first migrate all images to the phone, and then upload the images through the Nextcloud APP :smiley: