path.dirname(path)


path.dirname() 方法返回 path 的目录名,类似于 Unix 的 dirname 命令。尾随的目录分隔符会被忽略,见 path.sep

【The path.dirname() method returns the directory name of a path, similar to the Unix dirname command. Trailing directory separators are ignored, see path.sep.】

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

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

【A TypeError is thrown if path is not a string.】