How to get all the files from a directory ordered by file size in windows with VB.NET

1 Answer

0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim dir As String = "d:\source\_working_frame\"

        Dim files() As String = Directory.GetFiles(dir)

        Dim sorted_by_len() As String = files.OrderByDescending(
                     New Func(Of String, Integer)(Function(filename As String)
                                                      Return New FileInfo(filename).Length
                                                  End Function)).ToArray

        For Each element As String In sorted_by_len
            Console.WriteLine("{0} {1}b", element, New FileInfo(element).Length)
        Next

    End Sub

End Module


' run:
' 
' d:\source\_working_frame\wf.exe 16046234b
' d:\source\_working_frame\sqlite3.dll 599419b
' d:\source\_working_frame\wf.res 138128b
' d:\source\_working_frame\wf.ico 137040b
' d:\source\_working_frame\workingframe.sqlite 98304b
' d:\source\_working_frame\link.res 25092b
' d:\source\_working_frame\wf_main.pas 8237b
' d:\source\_working_frame\sqlite3.def 4309b
' d:\source\_working_frame\wf_main.lfm 2698b
' d:\source\_working_frame\wf_main.compiled 495b
' d:\source\_working_frame\wf.lpr 365b
' d:\source\_working_frame\output.txt 0b
'...

 



answered Oct 19, 2018 by avibootz
...