Method description:
Returns the directory of path. Similar to UNIX directory commands.
grammar:
The code copy is as follows:
path.dirname(p)
Since this method belongs to the path module, you need to introduce the path module before use (var path= require("path") )
Receive parameters:
p path address
example:
The code copy is as follows:
var path= require("path");
path.dirname('/foo/bar/baz/asdf/quux')
// returns
'/foo/bar/baz/asdf'
Source code:
The code copy is as follows:
exports.dirname = function(path) {
var result = splitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return root + dir;
};