parent-directory ( path -- parent )
Factor documentation > Factor handbook > Input and output > Pathnames
Next:file-name ( path -- string )


Vocabulary
io.pathnames

Inputs and outputs
patha pathname string
parenta pathname string


Word description
Strips the last component off a pathname.

Examples
USING: io io.pathnames ; "/etc/passwd" parent-directory print
/etc/


Definition
USING: kernel math sequences ;

IN: io.pathnames

: parent-directory ( path -- parent )
dup root-directory? [
trim-tail-separators dup last-path-separator
[ 1 + cut ] [ drop "." swap ] if
{ "" "." ".." } member? [ no-parent-directory ] when
] unless ;