• node的核心模块path


    //导入模块path
    var path=require("path");
    
    //path.basename :输出文件名+后缀
    //console.log(path.basename("shen
    odepath123.html"));  写反了
    console.log(path.basename("shen/node/path/123.html"));//123.html
    console.log(path.basename("shen/node/path/123"));//123
    
    //dirname()获取目录
    console.log(path.dirname("shen/node/path"));// node/02-node第二天
    
    //extname()获取文件的扩展名
    console.log(path.extname("shen/node/path/123.html"));//.html
    console.log(path.extname("shen/node/path/123"));//
    
    //join()合并路径
    var p1="node/path1/lala";
    var p2="node/path2/lili";
    console.log(path.join(p1,p2));//nodepath1lala
    odepath2lili
    
    //parse()把路径转换为一个对象
    console.log(path.parse("c:/shen/node/path/123.html"));
    //{ root: 'c:/',
    //    dir: 'c:/shen/node/path',
    //    base: '123.html',
    //    ext: '.html',
    //    name: '123' }
    
    //format()把一个路径对象转换成一个路径字符串
    var obj={ root: 'c:/',
        dir: 'c:/shen/node/path',
        base: '123.html',
        ext: '.html',
        name: '123' }
    console.log(path.format(obj));
    //c:/shen/node/path123.html
    
    //isAbsolute判断是否在根路径上
    console.log(path.isAbsolute("c:/shen/node/path123.html"));//true
    console.log(path.isAbsolute("node/path123.html"));//false
    console.log(path.isAbsolute("/node/path123.html"));//true
  • 相关阅读:
    Advanced Developer's Blog
    图片文字识别
    Unit test resources
    SpringBoot-mvn插件
    flask中使用proto3
    QTA-qtaf自动化测试实践
    AttributeError: module 'virtualenv' has no attribute 'create_environment'
    qtaf dick 报错 NameError: name 'dict_values' is not defined
    24点python实现
    mysql在win下移植
  • 原文地址:https://www.cnblogs.com/AnnieShen/p/6028407.html
Copyright © 2020-2023  润新知