[Solved] How to sort the files in the File List Box? lazarus / 21-General ---------------------------------------------------------------------- loaded · 2023-02-05 15:23 Hi All, I'm trying to view files in a specific folder in my respective application. But in the file list box it looks like sorting doesn't work. Attached is the correct view in the windows file explorer, and the wrong view in the file list box that belongs to me. Is there an easy way to do this? Or do we have to do the sorting ourselves? ---------------------------------------------------------------------- lainz · 2023-02-05 15:38 In your program is sorted but not respecting the numberd sorting. The sorting is an character sorting. Say 12 is less than 2 in alphabet. Not in numbers... ---------------------------------------------------------------------- loaded · 2023-02-05 16:02 Thanks for the reply lainz So what should we do so that the name order is the same as in the file explorer? Isn't there an easy way around this? ---------------------------------------------------------------------- wp · 2023-02-05 16:04 Quote from: loaded on February 05, 2023, 04:23:46 pmOr do we have to do the sorting ourselves? Yes... And you can put any degree of complexity into the compare function of your own. Here is a simple one, based on NaturalCompareText of unit StrUtils: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  StrUtils; function CompareByNumbers(List: TStringList; Index1, Index2: Integer): Integer;begin  Result := NaturalCompareText(List[Index1], List[Index2]);end; procedure TForm1.FormCreate(Sender: TObject);var  L: TStringList;begin  FileListbox1.Sorted := false;  FileListbox1.Directory := '.';  L := TStringList.Create;  try    L.Assign(FileListbox1.Items);    L.CustomSort(@CompareByNumbers);    FileListbox1.Items.Assign(L);  finally    L.Free;  end;end; ---------------------------------------------------------------------- loaded · 2023-02-05 16:22 It's spelled wp, it's pronounced King.  Yes, that's what I wanted, thank you very much.