标签:end base 函数 test window ant span 通过 处理
path模块提供了一些工具函数,用于处理目录的路径。
1.获取路径的扩展名
var extname = require(‘path‘).extname
2.通过当前目录获取想要的目录,用relative函数。
var path = require("path"); function test(){ var xx= path.relative(‘/‘, ‘../../‘); console.log(xx); } test(); //Users/anthonyliu
3.多种目录操作
var path = require("path"); console.log("__dirname"+__dirname); // /Users/anthonyliu/gfloan-hera/conf var folder = path.resolve(__dirname, "../"); console.log("folder="+folder); // /Users/anthonyliu/gfloan-hera var folderName = path.basename(folder); console.log("folderName="+folderName); //gfloan-hera var folderDir = path.dirname(folder); console.log("folderDir="+folderDir); // /Users/anthonyliu var confFolder = path.resolve(folderDir, "conf/" + folderName + ".conf"); console.log("confFolder="+confFolder); // /Users/anthonyliu/gfloan-hera/conf/default
4.提供不同操作系统的文件分隔符
path.sep //POSIX 为“/”;window 系统为\\
5.使路径正常化:
normalize(‘.‘ + sep + path) //来源于send包
标签:end base 函数 test window ant span 通过 处理
原文地址:https://www.cnblogs.com/liuyinlei/p/8836410.html