Have you tried these already existing, solved forum threads?
- Find latest File in a folder with respect to date Created - #13 by RishiVC1
- How to get latest file in folder using uipath - #5 by Palaniyappan
The solution suggests code very similar to your code here, but with slight difference.
I hope one of them will help you find what’s missing in your code.