path.basename(path[, ext])


返回 path 的最后一部分,类似于 Unix 中的 basename 命令。

path.basename('/foo/bar/baz/asdf/quux.html');
// 返回: 'quux.html'

path.basename('/foo/bar/baz/asdf/quux.html', '.html');
// 返回: 'quux'

如果 pathext 不是字符串,则抛出 TypeError

The path.basename() methods returns the last portion of a path, similar to the Unix basename command. Trailing directory separators are ignored, see path.sep.

path.basename('/foo/bar/baz/asdf/quux.html');
// Returns: 'quux.html'

path.basename('/foo/bar/baz/asdf/quux.html', '.html');
// Returns: 'quux'

A TypeError is thrown if path is not a string or if ext is given and is not a string.