append-path ( path1 path2 -- path )
Factor documentation > Factor handbook > Input and output > Pathnames
Prev:prepend-path ( path1 path2 -- path )
Next:normalize-path ( path -- path' )


Vocabulary
io.pathnames

Inputs and outputs
path1a pathname string
path2a pathname string
patha pathname string


Word description
Appends path1 and path2 to form a pathname.

Examples
USING: io.pathnames prettyprint ; "first" "second.txt" append-path .
"first/second.txt"


See also
prepend-path

Definition
USING: combinators io.pathnames.private kernel sequences ;

IN: io.pathnames

: append-path ( path1 path2 -- path )
{
{ [ over empty? ] [ append-path-empty ] }
{ [ dup empty? ] [ drop ] }
{ [ over trim-tail-separators "." = ] [ nip ] }
{ [ dup absolute-path? ] [ nip ] }
{
[ dup head.? ]
[ rest trim-head-separators append-path ]
}
{
[ dup head..? ]
[
2 tail trim-head-separators
[ parent-directory ] dip append-path
]
}
{
[
over absolute-path? over first path-separator?
and
]
[ [ 2 head ] dip append ]
}
[ append-relative-path ]
} cond ;