Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
parent-directory ( path -- parent )
Factor documentation
>
Factor handbook
>
Input and output
>
Pathnames
Next:
file-name ( path -- string )
Vocabulary
io.pathnames
Inputs and outputs
path
a pathname string
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
;