being pretty new to Scala can any one please kindly help me with a scenario where I need to get the file with latest modified date.
There are two scenarios. consider 2 directories ,
- dir1 (which has sub directories and files present inside each sub directory )
- dir2 (no sub directories but has only files )
for Scenario 1 - I need to get the file with latest modified date inside a latest modified date directory
for Scenario 2 - I just need the latest file with latest modified.
Please do help me in any way possible, I tried experiments with java.io file handling but haven't made any good progress.

This is my (untested) code to perform this operation on nested directories:
This is tail recursive and will compile to a simple loop.