basename

Description

The basename() function returns the file name portion from the provided path. basename actually works by searching the provided string for the rightmost token. A forward slash character (/) delimits tokens. basename ignores any number of trailing slash characters.

For example, given the string /one/two/three, basename returns the rightmost token, which in this case is three.

Given the string /one/two/, basename would ignore the trailing slash and return two.

Syntax

result = basename (path);

Arguments

path Required. Character string containing a file path and file name.

Return Values

result contains the rightmost token (that is, the file name) of the supplied character string (that is, the path name). An empty character string ("") is returned if no token is found.

result = basename ("/var/adm/pblog.txt");

In this example, result contains the file name pblog.txt.

For more information, see dirname.