How to find the most recent file in a directory using excluding the file with name "summary.pdf"?

Hi there,

I am currently using the below .net code to retrieve the last modified file:

new DirectoryInfo(Path).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).First().ToString

However there needs to be a extra validation to exclude the file name “summary.pdf” even if its the latest and consider only the remaining files names .

Could you please help on how to get the most recent file in a directly excluding a specific file name?

Thank you in advance.

Regards,
Vipin Jacob

@vipin.jacop Can you Check with this Expression :

new DirectoryInfo(Path).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).Select(Function(x)Not(x.Name.ToLower.Equals(“summary.pdf”))).First().ToString

3 Likes

Hi SupermanPuch,

First if all thank you for the help.

I tried but the expression was giving boolean values as result(True/ false) and not the file name.

Is there anything specific i need to get the file name?

Regards,
Vipin Jacob

@vipin.jacop My Apologies :sweat_smile:, This seems to be the right Expression :
new DirectoryInfo(Path).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).Where(Function(x)Not(x.Name.ToLower.Equals(“summary.pdf”))).First().ToString

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