Method description:
Return the directory of path. Similar to UNIX directory commands.
Grammar:
path.dirname(p)
Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )
Receive parameters:
p path address
Example:
var path= require("path");
path.dirname('/foo/bar/baz/asdf/quux')
// returns
'/foo/bar/baz/asdf'
Source code:
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;
};
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn