Here is a Zsh script that takes a starting folder name on the command line, gets the most recent modified file in that folder, prints it, and then begins its recursion into subfolders, where it prints the most recent modified file for the given folder. The output looks like the following though, for privacy, I have edited the full path output:
lastfile.zsh ~/Desktop/Metadata
2021-12-31 08:16:40 ~/Desktop/Metadata/cheetah_1k.jpg
2021-12-26 15:50:48 ~/Desktop/Metadata/SubDir/012C0507.CR
As you didn't mention any particular file type, I am using a wildcard for all files.
#!/bin/zsh
: <<"COMMENT"
Recurse into designated folder hierarchy printing last modified regular file in
the given folder. The syntax (.Nom[1]) means no dotfiles, and sort ascending on
modified date, taking the first [1] file from each folder.
COMMENT
# convert command line arguments using tilde to absolute path
START="${1:a:s/\~\//}"
function statfile () {
x=$(/usr/bin/stat -t '%Y-%m-%d %X' -f "%SB %N" "${1}")
printf '%s\n' $x
}
# get most recently modified file
statfile ${START}/*(.Nom[1])
# Zsh uses ** symbolism for folder recursion
# Here we are getting just the paths of the subfolders
for folder in "${START}"/**/*(/);
do
# now get the most recently modifed file in each subfolder
for file in "${folder}"/*(.Nom[1]);
do
statfile "${file}"
done
done
printf '%s\n' "Done."
exit 0