Mega Code Archive

 
Categories / Delphi / Files
 

How to convert long filenames in short filenames

Title: How to convert long filenames in short filenames uses Windows, SysUtils; function GetShortName(sLongName: string): string; var sShortName: string; nShortNameLen: Integer; begin SetLength(sShortName, MAX_PATH); nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH - 1); if (0 = nShortNameLen) then begin // handle errors... end; SetLength(sShortName, nShortNameLen); Result := sShortName; end; Usage Example: procedure TForm1.Button1Click(Sender: TObject); begin Caption := GetShortName('C:\Program Files\Delphi6\Lib\test.cnt'); // -- C:\PROGRA~1\Delphi6\Lib\test.cnt end;