Wikia

Delphi Programming

ExtractShortPathName Routine

2,918pages on
this wiki
Talk0
This page is intended as a supplement to the official documentation on Delphi programming. CodeGear is in the process of putting the Delphi documentation on the Web. Once they have done so, this page will link to the relevant page in the official documentation.
Stub
This article is a stub.
Please help enhance the Delphi Programming Wiki by expanding it.
Info
see the VCL Documentation Guidelines for an overview on doc pages

UnitEdit

DescriptionEdit

Definition (Delphi 6) (SysUtils Unit):

{$IFDEF MSWINDOWS}
function ExtractShortPathName(const FileName: string): string;
{$ENDIF}

Definition (Delphi 2010) (SysUtils Unit):

{$IFDEF MSWINDOWS}
function ExtractShortPathName(const FileName: string): string; overload;
{$ENDIF}

Definition (Delphi 2010) (AnsiStrings Unit):

{$IFDEF MSWINDOWS}
function ExtractShortPathName(const FileName: AnsiString): AnsiString; overload;
{$ENDIF}


This function will convert a given string FileName to it's short 8.3 form. It does this by calling the Windows function GetShortPathName or GetShortPathNameA (for the AnsiString Version).
If the file or directory does not exist an empty string will be returned. You can put the whole path in parameter FileName.

Technical CommentsEdit

(Known issues / Documentation clarifications / Things to be aware of)

ExamplesEdit

  //The next codeline will assume you have this file installed on your system
  //Path + Filename example: 
  //lShortPathAndFileName will be 'C:\PROGRA~1\WINDOW~1\Pinball\Pinball.exe'
  lShortPathAndFileName := ExtractShortPathName(
    'C:\Program Files\Windows NT\Pinball\Pinball.exe');

  //The next 2 codelines will assume you have this directory and file 
  //installed on your system
  SetCurrentDir('C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727');
  //Filename only example - lShortFileName will be 'ASPNET~1.EXE'
  lShortFileName := ExtractShortPathName('aspnet_compiler.exe');

  //The next codeline will assume you have this directory 
  //installed on your system
  //Path only example - lShortPathName will be 'C:\PROGRA~1'
  lShortPathName := ExtractShortPathName('C:\Program Files');

  //The next codeline will assume you DON'T have this file 
  //installed on your system
  //non existant File example:
  //lShortFileNameNotExistant will be '' (empty string) Since this file 
  //doesn't exist on the system
  lShortFileNameNotExistant := ExtractShortPathName(
    'C:\Program Files\Windows NT\Pinball\ThisFileDoesNotExist.exe');

See AlsoEdit

(Please provide links to items specifically related to this item.)

User Comments/TipsEdit

(Please leave your name with your comment.)

Around Wikia's network

Random Wiki