windows - 정렬 - 폴더 그룹 없애기
Windows 탐색기 에서처럼 델파이에서 정렬 순서를 얻는 방법? (2)
요약 :
- 내가 찾고있는 용어는 "자연스러운 정렬"인 것 같습니다.
운영 체제의 동작 :
- Windows (버전> = XP)의 경우 Windows 탐색기는 자연 정렬을 사용합니다.
- Linux 터미널의 경우 : 일반 "ls"대신 "ls -v"를 사용하여 자연 정렬하십시오.
Delphi에서 프로그래밍하려면 StrCmpLogicalW Windows API를 사용하여 자연 정렬을하십시오.
- Delphi & Kylix & Lazarus에서 프로그래밍하려면 수작업으로 함수를 사용하여 자연 정렬을하십시오.
- (1) Martin Pool의 Natural Order String Comparison을위한 Delphi wrapper.
http://irsoft.de/web/strnatcmp-and-natsort-for-delphi - (2) davekeolle 사이트의 다른 언어로 된 alphanum 정렬 알고리즘 코드.
http://www.davekoelle.com/alphanum.html - (3) 기타 지식 페이지 :
http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
http://objectmix.com/delphi/722211-natural-sorting-optimizing-working-solution.html
http://groups.google.com/group/borland.public.delphi.language.delphi.general/browse_thread/thread/1141d49f8bbba577
http://objectmix.com/delphi/401713-alphanumeric-sort-routine-delphi.html
- (1) Martin Pool의 Natural Order String Comparison을위한 Delphi wrapper.
==============
아래 그림과 같이 Windows 탐색기에서 다음 파일 이름이 정렬됩니다.
test_1_test.txt
test_2_test.txt
test_11_test.txt
test_12_test.txt
test_21_test.txt
test_22_test.txt
예를 들어 TStringList 인스턴스에 넣고 Sort를 호출하면 정렬 된 순서는 다음과 같습니다.
test_1_test.txt
test_11_test.txt
test_12_test.txt
test_2_test.txt
test_21_test.txt
test_22_test.txt
그리고 위의 파일 이름은 CentOS와 같은 Linux 배포판의 Cygwin 또는 xterm 터미널의 rxvt 터미널에서 아래에 표시된 순서대로 정렬됩니다.
test_11_test.txt
test_12_test.txt
test_1_test.txt
test_21_test.txt
test_22_test.txt
test_2_test.txt
이러한 정렬 행동의 차이를 이해하는 방법에 대해 의견을 제시하는 데 도움을 줄 수 있습니까? 또한 Windows 탐색기에서와 동일한 순서를 얻을 수 있습니까? 어떤 제안이라도 감사드립니다!
추신 : 내 Windows 로켈 중국어로 설정되어 있지만 영어 로케일 같은 생각할 것입니다.
Anders에게 감사드립니다. 대답은 StrCmpLogicalW입니다. Delphi 2009 소스에서 선언이 발견되지 않았으므로 아래 테스트에서 직접 선언했습니다.
type
TMyStringList = class(TStringList)
protected
function CompareStrings(const S1, S2: string): Integer; override;
end;
function StrCmpLogicalW(P1, P2: PWideChar): Integer; stdcall; external 'Shlwapi.dll';
function TMyStringList.CompareStrings(const S1, S2: string): Integer;
begin
Result:= StrCmpLogicalW(PChar(S1), PChar(S2));
end;
procedure TForm11.Button2Click(Sender: TObject);
var
SL: TMyStringList;
begin
SL:= TMyStringList.Create;
try
SL.Add('test_1_test.txt');
SL.Add('test_11_test.txt');
SL.Add('test_12_test.txt');
SL.Add('test_2_test.txt');
SL.Add('test_21_test.txt');
SL.Add('test_22_test.txt');
SL.Sort;
Memo1.Lines:= SL;
finally
SL.Free;
end;
end;
StrCmpLogicalW 는 숫자를 처리 할 수 있고, 다른 대안은 CompareString