Get files from folders and then get the latest one

Hi,

I need to get all files from folders for example I have three folders and files inside each. I have to get all files from all folders and then get the one that is the newest so I can later compare the date with another file.

Hi @markosc

What is the criteria for latest?
Modified Time or Creation Time

Creation time

@markosc

Try this

Directory.GetFiles("C:\TestFolder","*",SearchOption.AllDirectories).OrderBy(Function (x) Directory.GetCreationTime(x)).Last

Give the path of main folder inside which are the subfolders.

image

image

But I said I have more then one folder for example:
image

Then I have to get files from both folders and then from the file list get the latest created one.

@markosc

Please see the updated post

Directory.GetFiles("C:\TestFolder","*",SearchOption.AllDirectories).OrderBy(Function (x) Directory.GetCreationTime(x)).Last

Give the path of main folder inside which are the subfolders.

image

image

1 Like

Thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.