Click or drag to resize

SplitPath Function (Psz, Psz, Psz, Psz, Psz)

X#

Note: This API is now obsolete.

Break a path name into its components.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
[ObsoleteAttribute("'SplitPath()' with PSZ arguments is no longer supported. Please use SplitPath() or _SplitPath() (both with STRING arguments) in stead", 
	FALSE)]
 FUNCTION SplitPath(
	pszPathName AS PSZ,
	pszDrive AS PSZ,
	pszDir AS PSZ,
	pszFile AS PSZ,
	pszExt AS PSZ
) AS VOID
Request Example View Source

Parameters

pszPathName
Type: Psz
The path name to break.
pszDrive
Type: Psz
The drive letter followed by a colon. pszDrive must contain 2 bytes, plus 1 byte for the terminating _Chr(0) character.
pszDir
Type: Psz
The directories, including the trailing slash.
Forward slashes and backslashes both may be present in pszFile.
Forward slashes (/) are converted to backslashes (\). pszDir must contain 255 bytes, plus 1 byte for the terminating _Chr(0) character.
pszFile
Type: Psz
The file name, without the extension. pszFile must contain 255 bytes, plus 1 byte for the terminating _Chr(0) character.
pszExt
Type: Psz
The extension, including the leading period. pszExt must contain 7 bytes, plus 1 byte for the terminating _Chr(0) character.

Return Value

Type: 
Remarks
SplitPath() breaks a path name into its components and stores the result in the supplied arguments.
The supplied arguments must have enough space to hold the maximum possible size of the broken components.
If any of the components is missing in the path name, the corresponding argument is truncated to a 0 length.
Examples
This example breaks a full path name into its four components:
X#
 1FUNCTION Start()
 2    LOCAL cDrive, cDir, cFile, cExt AS STRING
 3    MySplitPath("c:\develop\myprg\hello.prg", ;
 4        @cDrive, @cDir, @cFile, @cExt)
 5    ? cDrive            // C:
 6    ? cDir            // \DEVELOP\MYPRG
 7    ? cFile            // HELLO
 8    ? cExt             // .PRG
 9FUNCTION MySplitPath(cPath AS STRING,    ;
10    cDrive REF STRING,            ;
11    cDir REF STRING,            ;
12    cFile REF STRING,            ;
13    cExt REF STRING)
14    LOCAL pszPath, pszDrive, pszDir AS PSZ
15    LOCAL pszFile, pszExt AS PSZ
16    LOCAL cb
17    pszPath := MemAlloc(cb := SLen(cPath) + 1)
18    MemCopy(pszPath, PTR(_CAST, cPath), cb)
19    pszDrive := MemAlloc(2+1)
20    pszDir   := MemAlloc(255+1)
21    pszFile  := MemAlloc(255+1)
22    pszExt   := MemAlloc(7+1)
23    SplitPath(cPath, pszDrive, pszDir,    ;
24        pszFile, pszExt)
25    cDrive := Psz2String(pszDrive)
26    cDir   := Psz2String(pszDir)
27    cFile  := Psz2String(pszFile)
28    cExt   := Psz2String(pszExt)
29    MemFree(pszDrive)
30    MemFree(pszDir)
31    MemFree(pszFile)
32    MemFree(pszExt)
33    RETURN
This example shows that the supplied argument is truncated to 0 length if its corresponding component is missing in the path name:
X#
1FUNCTION Start()
2    LOCAL cDrive, cDir, cFile, cExt AS STRING
3    MySplitPath("c:\develop\myprg\hello", ;
4        @cDrive, @cDir, @cFile, @cExt)
5    ? cDrive            // C:
6    ? cDir            // \DEVELOP\MYPRG
7    ? cFile            // HELLO
8    ? SLen(cExt)         // 0
See Also