SplitPath


The SplitPath method extracts folder name and file name from specified path, optionally expanded to absolute path.
C++
long SplitPath(
  LPSTR Path,                        // path
  LPSTR FolderName,                  // buffer that receives folder name
  long FolderLength,                 // size of folder buffer
  LPSTR FileName,                    // file name
  long FileLength,                   // size of file buffer
  BOOL Expand = FALSE                // path expansion flag
);
long SplitPath(
  LWPSTR Path,                       // path
  LWPSTR FolderName,                 // buffer that receives folder name
  long FolderLength,                 // size of folder buffer
  LWPSTR FileName,                   // file name
  long FileLength,                   // size of file buffer
  BOOL Expand = FALSE                // path expansion flag
);
BASIC
SplitPath(
  Path As Variant,                   // path
  Optional FolderName As Variant,    // folder name
  Optional FileName As Variant,      // file name
  Expand As Boolean = False          // path expansion flag
) As String

Parameters

Path
C++
Pointer to buffer containing path (must be NULL terminated).
BASIC
Variant containing path.
Variant must be of String data type; it must not be an array.
FolderName
C++
Pointer to buffer that receives folder name.
Buffer must be large enough to accept at most FolderLength + 1 characters.
This parameter can be NULL if folder name is not required.
BASIC
Variant that receives name of the folder.
Variant must be of String data type; it must not be an array.
Variant can be uninitialized - in such case it is converted to String.
This parameter can be omitted if folder name is not required.
C++
FolderLength
Size of folder buffer; if folder name is longer than FolderLength, error is returned.
FileName
C++
Pointer to buffer that receives file name.
Buffer must be large enough to accept at most FileLength + 1 characters.
This parameter can be NULL if file name is not required.
BASIC
Variant that receives file name.
Variant must be of String data type; it must not be an array.
Variant can be uninitialized - in such case it is converted to String.
This parameter can be omitted if file name is not required.
C++
FileLength
Size of file buffer; if file name is longer than FileLength, error is returned.
Expand
Expansion flag that determines behaviour of the method when specified path is not absolute.
If this parameter is TRUE and specified path is relative, it is expanded to absolute path.

Return Values

If the method succeeds, the return value is 0.
If the method fails, the return value is failure code and error code is set. Call GetError to get error code.

Remarks

Method does not check if Path actually specifies physical file. File name is retrieved by simply extracting tail part of Path located by last (back)slash. Therefore method can be used to split paths containing subfolders only. If Expand is set, specified path is expanded to absolute path with drive letter and directory before splitting.

Unicode version of the method should not be confused with Unicode system calls or Unicode text data. All versions of the method can be used on Unicode and non-Unicode systems depending on your needs. On Unicode systems, however, folder name and file name is extracted using Unicode version of system functions (unless Unicode is disabled with EnableUnicode method). Conversion between ANSI and Unicode is performed internally according to current codepage which can be changed with SetCodePage method. See Unicode Support for more information on Unicode system calls, Unicode methods and Unicode text data.

See Also

MakePath, File System Operations