Sort files by size in ascending order

Hi Everyone,

I need help on the below scenario.

I need to sort files by size in ascending order and store the result in a list.

Currently I am giving a root path and using SearchOption.Alldirectories to get specific type of files which i require in a list but i want to sort it in ascending order, like the file with the least size comes at first and with the big at the last.

Please help!


Hello @Dhruvi_Arumugam,

Try with this linq query where the lstFiles is List(Of FileInfo) Datatype. Also check the attached workflow

lstFiles.Where(Function(f) f.FullName IsNot Nothing).OrderByDescending(Function(f) f.Length).ToList

FilesSortBySize.xaml (5.8 KB)

Hi @sarathi125,

I want to order it in smaller to larger, will this work here ?



Yes, instead of “OrderByDescending” use “OrderBy” alone in the Linq Query

Directory.GetFiles(Fol_Path).OrderBy(Function(F) New Fileinfo(F).Length).Toarray


Directory.GetFiles(Fol_Path).OrderBy(Function(F) New Fileinfo(F).SizeInKB).ToArray

1 Like


the list i have is a sting list not List(Of FileInfo) can you guide on that.


@Dhruvi_Arumugam Ref to the below one