Share this page 

Convert a short pathname to a longTag(s): Powerscript


The API GetLongPathName was introduced with Win98 and is unavailable on Win95 or WinNT but OK with XP.

[local external definition]
FUNCTION ulong GetLongPathName( &
  REF String lpszShortPath, &
  REF String lpszLongPath, &
  ULong cchBuffer ) &
LIBRARY "kernel32.dll" ALIAS FOR "GetLongPathNameA"


[powerscript]
ContextKeyword lcxk_base
string ls_path_short
string ls_path_long
string ls_values[]

this.GetContextService("Keyword", lcxk_base)
lcxk_base.GetContextKeywords("temp", ls_values)
IF Upperbound(ls_values) > 0 THEN
   ls_path_short = ls_values[1]
ELSE
   ls_path_short = "*UNDEFINED*"
END IF

MessageBox("short",ls_path_short)

// ex :  C:\DOCUME~1\Real\LOCALS~1\Temp

ls_path_long = space(255)

GetLongPathName(ls_path_short, ls_path_long, 255);

MessageBox("long",ls_path_long)

// ex :  C:\Documents and Settings\Real\Local Settings\Temp

To do the conversion long to short, use GetShortPathName API. In PB10, you may need to use the Unicode version, so use the "ALIAS GetLongPathNameW" instead.