c# – Long files names – Education Career Blog

How to get the longest files names in a directory using C#?


    .OrderByDescending(s => s.Length)


var filelist = Directory.GetFiles(<directorypathandname>);
var result = filelist.Where( f => f.Length == filelist.Max( f2 => f2.Length));

Now result will contain all files with the longest name. Usually only one I guess, but all of them if they have identical length, and is longest.

Leave a Comment