Kbase P167077: 4GL/ABL: How to Call WIN32 API Function: GetLongPathName?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  6/1/2010 |
|
Status: Unverified
GOAL:
4GL/ABL: How to Call WIN32 API Function: GetLongPathName?
GOAL:
How to get the long path name of a Windows file or directory?
GOAL:
How to get the short and long path names of a Windows file or directory?
FACT(s) (Environment):
Windows
Progress 9.x
OpenEdge 10.x
FIX:
The following code returns the TEMP directory in a short form containing the tilde '~' special character. For example: "C:\DOCUME~1\CONFIG~1\Temp". The FILE-INFO system handle fails to process this form correctly correctly even after the tilde '~' is replaced with '~~':
DEFINE VARIABLE vc_tempdir AS CHARACTER NO-UNDO.
/*** Read the environment variable ***/
vc_tempdir = OS-GETENV("TEMP").
/*** Replace the special character for double ***/
vc_tempdir = REPLACE(vc_tempdir,"~~","~~~~").
FILE-INFO:FILE-NAME = vc_tempdir.
MESSAGE "vc_tempdir equals to: " vc_tempdir SKIP
"FILE-INFO value: " FILE-INFO:FULL-PATHNAME
VIEW-AS ALERT-BOX INFO BUTTONS OK.
One solution to this problem is to call the WIN32 API Function: GetLongPathName as per the following example:
DEFINE VARIABLE vc_shortdirname AS CHARACTER NO-UNDO.
DEFINE VARIABLE vc_longdirname AS CHARACTER NO-UNDO.
DEFINE VARIABLE TxtLength AS INTEGER NO-UNDO.
ASSIGN
vc_shortdirname = OS-GETENV("TEMP")
vc_longdirname = FILL(chr(32), 256).
RUN GetLongPathNameA
(
INPUT OS-GETENV("TEMP"),
OUTPUT vc_longdirname,
INPUT LENGTH(vc_longdirname),
OUTPUT TxtLength
).
MESSAGE
"Short name dir:~t" vc_shortdirname "~n"
"Long name dir:~t" vc_longdirname "~n"
"Directory Length:~t" TxtLength
VIEW-AS ALERT-BOX INFO BUTTONS OK.
PROCEDURE GetLongPathNameA EXTERNAL "kernel32.dll":
DEFINE INPUT PARAMETER vc_shortname AS CHARACTER.
DEFINE OUTPUT PARAMETER vc_longname AS CHARACTER.
DEFINE INPUT PARAMETER vi_nSize AS LONG.
DEFINE RETURN PARAMETER vn_textlength AS LONG.
END PROCEDURE.