1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
| function GetShortPath(Path: string; Count: Integer): string;
procedure Slashes(var Str: string; var Num: Integer); var Position, Index: Integer; begin Index:=0; repeat Position:=Pos('\', Str); Delete(Str,1,Position); if Position<>0 then Inc(Index); if (Index=Num)and(Num<>0) then break; until Position=0; Num:=Index; end;
var Num, NewNum, P: Integer; Str: string; begin Str:=Path; Num:=0; Slashes(Path, Num); while (Length(Str)>Count)and(Num>2) do begin NewNum:=Num div 2; Path:=Str; Slashes(Path, NewNum); P:=Pos(Path, Str); Delete(Str,P, Length(Path)); NewNum:=2; Slashes(Path, NewNum); Str:=Str+'...\'+Path; Dec(Num); end; Result:=Str; end;
procedure TForm1.ButtonClick(Sender: TObject); var MEDIA : String; begin MEDIA:= 'F:\@_MP3\@_MP3-1\Daliah Lavi - Very Best of\08 - Daliah Lavi - Oh wann kommst du.mp3'; Label1.Caption:= GetShortPath(MEDIA,30); end; |