std.basename
Available inall subroutines.
Breaks a pathname into the filename component and returns it. A pathname is a
forward slash-separated list of directory names followed by either a directory
name or a filename. Trailing /
characters are not counted as part of the
pathname. Both relative and absolute pathnames are allowed. Relative pathnames
may use a single dot (.) or double dots (..) to represent the current directory
or the parent directory respectively.
In the usual case, std.basename
returns the component following the final
/
: for example, std.basename("/foo/bar/foobar")
is "foobar"
.
If the pathname does not contain a forward slash, then std.basename
returns a
copy of the pathname: for example, std.basename("foo")
is "foo"
.
If the pathname only contains one or more forward slashes, then std.basename
returns the string "/"
: for example, std.basename("/")
is "/"
.
If the pathname is an empty string ""
, then std.basename
returns the string
"."
. The same behavior applies if std.basename
is invoked with a not-set
header for the pathname: for example, std.basename(req.http.Not-Set)
is
"."
.
Concatenating the string returned by
std.dirname
, a "/"
, and the string
returned by std.basename
yields a complete pathname.
For example, std.dirname("fastly.com/api") "/" std.basename("fastly.com/api")
is "fastly.com/api"
.
See std.dirname
for breaking a pathname
into the directory component.
This function conforms to POSIX.1-2001.
Examples
std.basename("") # returns "."std.basename("/usr/lib") # returns "lib"std.basename("/usr/") # returns "usr"std.basename("usr") # returns "usr"std.basename("/") # returns "/"std.basename(".") # returns "."std.basename("..") # returns ".."