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.
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.
See Also: join_path