How would I find the grav page folder that has the most recent file?

I want to have a most recent photo feature on my homepage.

{% for p in page.find('/photography').children.order('date', 'desc').slice(0, 1) %}

The above code finds the most recent page in a blog but what I want to do is find the folder that has the most recent photo in it. My folder structure is like this:

photo gallery
- album 1
  -picture1.jpg
  -picture2.jpg
- album 2
  -picture1.jpg
  -picture2.jpg

So when I drop a new photo in one of the folders, I want the homepage to know which folder has the newest file.

this is a little tricky because the latest media modification date is not trickled up into page, so you have to go digging to get it. Read through it and it should make sense what it’s doing…

This is in Twig-friendly sytnax, but could easily be converted into pure PHP (as in a plugin).

{% set newest_image = '' %}
{% set newest_image_timestamp = 0 %}

{% for album in page.children %}
  {% for image in album.media.images %}
    {% if image.get('modified') > newest_image_timestamp %}
      {% set newest_image_timestamp = image.get('modified') %}
      {% set newest_image = image %}
    {% endif %}
  {% endfor %}
{% endfor %}

Newest Image: {{ newest_image }}

Thanks again @rhukster. I will work with this and try to pull the grav page name too so i can make a link to the album. I will post my code when done but I am away right now. This would be a good plugin to have, I will see if there is anything similar already.

Here is the code that links the image to the gallery.

{% set newest_image = '' %}
{% set newest_image_timestamp = 0 %}
{% set newest_image_folder = '' %}

{% for album in page.find('/photography').children %}
  {% for image in album.media.images %}
    {% if image.get('modified') > newest_image_timestamp %}
      {% set newest_image_timestamp = image.get('modified') %}
      {% set newest_image_folder = album.url %}
      {% set newest_image = image %}
    {% endif %}
  {% endfor %}
{% endfor %}

Newest Image: <a href="{{ newest_image_folder }}">{{ newest_image.cropResize(300, 300) }}</a>