1.path.basename(path[, ext]) ● path <string> ● ext <string> An optional file extension ● Returns: <string> 只会返回路径的最后一部分 第二个参数用于截取 path.basename('/foo/bar/baz/asdf/quux.html'); // Returns: 'quux.html' path.basename('/foo/bar/baz/asdf/quux.html', '.html'); // Returns: 'quux' 2.path.dirname(path) ● path <string> ● Returns: <string> 用于返回文件目录路径 path.dirname('/foo/bar/baz/asdf/quux'); // Returns: '/foo/bar/baz/asdf' 3.path.extname(path) ● path <string> ● Returns: <string> 用于返回路径文件的后缀名 path.extname('index.html'); // Returns: '.html' path.extname('index.coffee.md'); // Returns: '.md' path.extname('index.'); // Returns: '.' path.extname('index'); // Returns: '' path.extname('.index'); // Returns: '' 4.path.isAbsolute(path) ● path <string> ● Returns: <boolean> 判断是否是绝对路径 path.isAbsolute('//server'); // true path.isAbsolute('\\server'); // true path.isAbsolute('C:/foo/..'); // true path.isAbsolute('C:\foo\..'); // true path.isAbsolute('bar\baz'); // false path.isAbsolute('bar/baz'); // false path.isAbsolute('.'); // false 5.path.join([...paths]) ● ...paths <string> A sequence of path segments ● Returns: <string> 将字符串路径连接起来 path.join('/foo', 'bar', 'baz/asdf', 'quux', '..'); // Returns: '/foo/bar/baz/asdf' path.join('foo', {}, 'bar'); // throws 'TypeError: Path must be a string. Received {}' 6.path.normalize(path) ● path <string> ● Returns: <string> path.normalize('/foo/bar//baz/asdf/quux/..'); 7.path.parse(path) ● path <string> ● Returns: <Object> path.parse('/home/user/dir/file.txt'); // Returns: // { root: '/', // dir: '/home/user/dir', // base: 'file.txt', // ext: '.txt', // name: 'file' } 8.path.relative(from, to) ● from <string> ● to <string> ● Returns: <string> 从一个路径到另一个路径的相对路径 path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb'); // Returns: '../../impl/bbb' 9.path.resolve([...paths]) ● ...paths <string> A sequence of paths or path segments ● Returns: <string> 从右向左执行,直到绝对路径为止;如果路径执行完成还未找到绝对路径;则自动添加当前目录路径,注意:会执行 .. path.resolve('/foo/bar', './baz'); // Returns: '/foo/bar/baz' path.resolve('/foo/bar', '/tmp/file/'); // Returns: '/tmp/file' path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif'); // if the current working directory is /home/myself/node, // this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'