file split

file split name

Returns a list whose elements are the path components in name. The first element of the list will have the same path type as name. All other elements will be relative.

Keep ambiguous path separators

Path separators will be discarded unless they are needed ensure that an element is unambiguously relative. For example, under Unix

 file split /foo/~bar/baz

returns / foo ./~bar baz to ensure that later commands that use the second component do not attempt to perform tilde substitution.


Discard double "//"

HaO 2017-04-10:

It might be a side effect, but the following combination may be used to discard double "//" within the specification:

file join {*}[file split $Path]

Example:

% file split //a//b/c//d.txt
//a/b c d.txt
% file join {*}[file split //a//b/c//d.txt]
//a/b/c/d.txt

A "//" is allowed at the beginning to specify network resouces (at least on windows), but not within the path. So, a leading "//" must be preserved, while all others are removed.


See also