Handbook
Glossary
parent-directory ( path -- parent )
Factor handbook
»
Input and output
»
Pathnames
Next:
file-name ( path -- string )
Vocabulary
io
.
pathnames
Inputs
path
a pathname string
Outputs
parent
a 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
;