zoukankan      html  css  js  c++  java
  • Node.js之Path模块

    Node.js path 模块提供了一些用于处理文件路径的小工具,我们可以通过以下方式引入该模块:

    const path = require("path")

    方法

    1、path.join([path1][, path2][, ...]):

    const path = require("path");
    
    console.log(path.join(__dirname + "/index.html" + "/abc" + ".../" + "123")); // G:work
    ode
    ode1index.htmlabc...123
    console.log(path.join(__dirname + "/index.html" + "/abc" + "/.../" + "123")); // G:work
    ode
    ode1index.htmlabc...123
    console.log(path.join(__dirname + "/index.html" + "/abc" + "/../" + "123")); // G:work
    ode
    ode1index.html123
    console.log(path.join(__dirname + "/index.html" + "/abc" + "../" + "123")); // G:work
    ode
    ode1index.htmlabc..123
    console.log(path.join(__dirname + "/index.html" + "/abc" + "/./" + "123")); // G:work
    ode
    ode1index.htmlabc123
    console.log(path.join(__dirname + "/index.html" + "/abc" + "./" + "123")); // G:work
    ode
    ode1index.htmlabc.123
     

    拼接方式:

    1)先连接,连接时去掉“”等特殊字符;

    2)连接后处理"/../"和"/./"情况。

  • 相关阅读:
    C# 文件类的操作---删除
    C#实现Zip压缩解压实例
    UVALIVE 2431 Binary Stirling Numbers
    UVA 10570 meeting with aliens
    UVA 306 Cipher
    UVA 10994 Simple Addition
    UVA 696 How Many Knights
    UVA 10205 Stack 'em Up
    UVA 11125 Arrange Some Marbles
    UVA 10912 Simple Minded Hashing
  • 原文地址:https://www.cnblogs.com/samve/p/14208970.html
Copyright © 2011-2022 走看看