Skip to content

Modern Fs PathSplit

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Filesystem › Filesystem Library › PathSplit

PathSplit

Splits a normalised path into its parts, without the root, in an Array; returns the count.

Syntax

PathSplit( p, comps )

Notes

  • fills an Array( of ustring ); returns the count

Examples

#import "std/containers"
#import "std/fs"
using fs, containers

'' Fills an Array with the components and returns the count.
''
'' THE ROOT IS NOT A COMPONENT. "C:\dev\src\main.tiko" splits into
'' three, not four -- PathRoot joined with these reconstructs the
'' normalised path, and that is the round trip the split guarantees.
dim parts as Array( of ustring )
dim as int32 n = PathSplit( "C:\dev\src\main.tiko", parts )

print n                      '' 3
for i as int32 = 0 to parts.Count - 1
    print parts[ i ]         '' dev / src / main.tiko
next

print PathRoot( "C:\dev\src\main.tiko" )      '' C:\  -- the missing piece

'' It splits the NORMALISED path, so "." and ".." are already resolved
'' and never come back as components

Library: Filesystem Library
Category: Filesystem
Documented under: Paths

Clone this wiki locally