Expand/Shrink

split_path

Definition: sequence res = split_path(string path, bool preservetrailsep=false)
Description: The logical counterpart to join_path(), split_path() breaks up a path into a sequence of path fragments.

Returns a sequence of sub-strings of path.
pwa/p2js: Supported. Not that it’s very likely to be useful, but it is just string manipulation, so there’s little point in deliberately disabling it.
Comments: Paths are split on either Windows ('\\') or Linux ('/') separators.
A leading separator is always preserved, and any consecutive ones are skippped.

Note that any preserved cross-platform path separators may cause issues, see technicalia.
Example 1:
?split_path(`C:\Program Files (x86)\Phix\demo\edix`)
        -- {`C:`,`Program Files (x86)`,`Phix`,`demo`,`edix`}
?split_path(`demo\edix`)                            -- {`demo`,`edix`}
?split_path(`\demo\edix`)                           -- {`\demo`,`edix`}
?split_path(`usr/home/john`)                        -- {`usr`,`home`,`john`}
?split_path(`/usr/home/john`)                       -- {`/usr`,`home`,`john`}
?split_path(`demo\edix\`)                           -- {`demo`,`edix`}
?split_path(`demo\edix\`,preservetrailsep:=true)    -- {`demo`,`edix\`}
?split_path(`demo\edix`,preservetrailsep:=true)     -- {`demo`,`edix`}
?split_path(`demo/edix/`)                           -- {`demo`,`edix`}
?split_path(`demo/edix/`,preservetrailsep:=true)    -- {`demo`,`edix/`}
?split_path(``)                                     -- {}

The use of a named parameter for preservetrailsep makes the intent much clearer.
Implementation: See builtins\psplit.e (an autoinclude) for details of the actual implementation.
See Also: join_path
Expand/Shrink