/**
* Created by SlzStar on 2017/9/18.
*/
//操作路径;
var path = require("path");
//定义文件路径;
var newPath = "/user/index.html";
/*
返回路径字符串的对象;path.parse();
{ root: '/',
dir: '/user',
base: 'index.html',
ext: '.html',
name: 'index' }
*/
console.log(path.parse(newPath));
//获取路径名;path.dirname();
console.log(path.dirname(newPath)) // /user
//获取拓展名;path.extname()
console.log(path.extname(newPath)) // ./html
//获取完整文件名;
console.log(path.basename(newPath)) //index.html
//用于连接路径;path.join();
console.log(path.join("./", "/user", "./index.html")); //user\index.html
//用于将相对路径转换为绝对路径;从一个参数的路径到另一个参数的路径,该怎么走;
console.log(path.relative("./user/index.html", "./use/list.html")); //..\..\use\list.html
//将to参数解析为绝对路径;path.resolve([from ...], to);
console.log(path.resolve("./index.html")) //D:\webStorm-file\9-18-sunlizhen\index.html
//判断参数是否是绝对路径;isAbolute(path); 是返回true 不是返回false
console.log(path.isAbsolute(newPath)); //true
//从对象中返回路径字符创,与path.parse相反;path.format();
var user = {
dir : './user/index',
ext : '.html',
base : 'index.html'
}
console.log(path.format(user)); // ./user/index\index.html
* Created by SlzStar on 2017/9/18.
*/
//操作路径;
var path = require("path");
//定义文件路径;
var newPath = "/user/index.html";
/*
返回路径字符串的对象;path.parse();
{ root: '/',
dir: '/user',
base: 'index.html',
ext: '.html',
name: 'index' }
*/
console.log(path.parse(newPath));
//获取路径名;path.dirname();
console.log(path.dirname(newPath)) // /user
//获取拓展名;path.extname()
console.log(path.extname(newPath)) // ./html
//获取完整文件名;
console.log(path.basename(newPath)) //index.html
//用于连接路径;path.join();
console.log(path.join("./", "/user", "./index.html")); //user\index.html
//用于将相对路径转换为绝对路径;从一个参数的路径到另一个参数的路径,该怎么走;
console.log(path.relative("./user/index.html", "./use/list.html")); //..\..\use\list.html
//将to参数解析为绝对路径;path.resolve([from ...], to);
console.log(path.resolve("./index.html")) //D:\webStorm-file\9-18-sunlizhen\index.html
//判断参数是否是绝对路径;isAbolute(path); 是返回true 不是返回false
console.log(path.isAbsolute(newPath)); //true
//从对象中返回路径字符创,与path.parse相反;path.format();
var user = {
dir : './user/index',
ext : '.html',
base : 'index.html'
}
console.log(path.format(user)); // ./user/index\index.html