Click or drag to resize

SplitPath Function (String, String, String, String, String)

X#
Break a path name into its components.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION SplitPath(
	pszPathName AS STRING,
	pszDrive REF STRING,
	pszDir REF STRING,
	pszFile REF STRING,
	pszExt REF STRING
) AS VOID
Request Example View Source

Parameters

pszPathName
Type: String
The path name to break.
pszDrive
Type: String
The drive letter followed by a colon. pszDrive must contain 2 bytes, plus 1 byte for the terminating _Chr(0) character.
pszDir
Type: String
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: String
The file name, without the extension. pszFile must contain 255 bytes, plus 1 byte for the terminating _Chr(0) character.
pszExt
Type: String
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