How to loop through Folder structure and get files

I have this folder Structure:
\serverName\ExternalData:
BPM
CRM
DDM

I want to go through these folders, 1st one: \serverName\ExternalData\BPM and get the latest file, process it (take two fields and put it in the list, I have a code for this)

Then go to the second folder: \serverName\ExternalData\CRM, get the latest file, process it (take two fields and put it in the list, a different list, I have a code for this as well)

Then do the same of the third folder(DDM folder)

Please help.

In Python I’d do that with pathlib: Path.iterdir() to get the files, and assuming you mean “latest” by modification time Path.stat() to get that for each file. Create a variable holding a reference to the latest file seen in the iteration, and update it when the iteration encounters a newer one.

Most other programming languages will have similar functions.