Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.688 Beiträge
 
Delphi 11 Alexandria
 
#19

AW: Dateinamen auslesen und sortieren

  Alt 6. Apr 2023, 20:05
Wie wäre es hiermit? Getestet mit Delphi Alexandria um eine "logische" Sortierung zu implementieren, dabei ist dann das "Kapitel" da wo es sein sollte.
Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  System.Classes;

function StrCmpLogicalW(P1, P2: PWideChar): Integer; stdcall; external 'Shlwapi.dllname 'StrCmpLogicalW';

function CompareProc(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := StrCmpLogicalW(PChar(List[Index1]), PChar(List[Index2]));
end;

var
  SL: TStringList;
  i: Integer;
begin
  try
    SL := TStringList.Create;
    try
      SL.Add('2.6.1.csv');
      SL.Add('4.5.csv');
      SL.Add('4.9.1.csv');
      SL.Add('1.3.csv');
      SL.Add('2.3.csv');
      SL.Add('2.6.2.csv');
      SL.Add('1.7.csv');
      SL.Add('4.9.2.csv');
      SL.Add('1.6.csv');
      SL.Add('2.8.csv');
      SL.Add('2.6.3.csv');
      SL.Add('4.8.csv');
      SL.Add('2.12.csv');
      SL.CustomSort(@CompareProc);
      for i := 0 to Pred(SL.Count) do
        WriteLn(SL[i]);
    finally
      SL.Free;
    end;
    ReadLn;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Zitat:
1.3.csv
1.6.csv
1.7.csv
2.3.csv
2.6.1.csv
2.6.2.csv
2.6.3.csv
2.8.csv
2.12.csv
4.5.csv
4.8.csv
4.9.1.csv
4.9.2.csv
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat