Calc BASIC : How to get and sort filenames from a folder?

From this answer to the question,

the result is the list of unsorted filenames.

How can we sort those filenames in macros ?

Just insert between Loop and End Sub two lines

oSheet.getCellByPosition(0,0).setString("Files")
sortRange(ThisComponent, oSheet.getCellRangeByPosition(0, 0, 0, iCounter))

and add after End Sub new subroutine:

Sub sortRange(oDoc As Variant, oRange As Variant)
Dim aSortFields(0) As New com.sun.star.util.SortField
Dim aSortDesc(1) As New com.sun.star.beans.PropertyValue
	oDoc.getCurrentController.select(oRange)
	aSortFields(0).Field = 0
	aSortFields(0).SortAscending = TRUE
	aSortDesc(0).Name = "SortFields"
	aSortDesc(0).Value = aSortFields()
	aSortDesc(1).Name = "ContainsHeader"
	aSortDesc(1).Value = True
	oRange.Sort(aSortDesc())
End Sub

Nothing else.

Dear @JohnSUN

Thank you so much.