SplitPath command

Requires: GfaWinx.lg32

Purpose

Breaks a path name (UNC included) into its components drive, directory, filename, and extension.

Syntax

SplitPath FName$, Drive$, Dir$, FileName$, Ext$

FName$: string expression
Drive$, Dir$, FileName$, Ext$: string variables

Description

SplitPath parses the filepath from the string expression FName and stores it's components drive, directory, filename, and extension in the specified string variables. SplitPath handles both normal path and UNC path expressions.

After parsing Drive$ contains the drive-letter plus : ("X:"), Dir$ contains the path starting and ending with a backslash ("\path\sub\"), FileName$ contains the filename without extension, and Ext$ holds the extension starting with the dot (".ext").

When FName is an UNC path specification Drive$ which contains the first part starting with \\ until (but without) the next backslash ("\\MyServer"), the other values are the same.

Example

$Library "gfawinx"

Debug.Show

Local String sDrive, sDir, sFileName, sExt

SplitPath  "C:\WINDOWS\SYSTEM.INI", sDrive, sDir, sFileName, sExt

Trace sDrive    ' "C:"

Trace sDir      ' "\WINDOWS\"

Trace sFileName ' "SYSTEM"

Trace sExt      ' ".INI"

SplitPath "\\MyServer\Drive-C\MyDir\file.ext", sDrive, sDir, sFileName, sExt

Trace sDrive    ' "\\MyServer"

Trace sDir      ' "\Drive-C\MyDir\"

Trace sFileName ' "file"

Trace sExt      ' ".ext"

Remarks

SplitPath is compatible with the C library function _splitpath().

See Also

Dir, FileName(ShowOpen)

{Created by Sjouke Hamstra; Last updated: 24/08/2021 by James Gaite}