w88975
V2EX  ›  Node.js

在 Node 中如何判断 A 文件是否属于 A/B/C 目录下?

  •  
  •   w88975 · Jan 13, 2016 · 3445 views
    This topic created in 3963 days ago, the information mentioned may be changed or developed.

    文件: src/js/lib/xxx/a.js
    如何判断该文件是否属于一个目录下

    src/js/xxx // true
    src/js/ // true
    src/ //true
    test/xxx/ //false

    5 replies  •  2016-01-20 16:43:43 +08:00
    yeyeye
    yeyeye
    Jan 13, 2016
    1
    搜索 src 所在位置
    chemzqm
    chemzqm
    Jan 14, 2016
    2
    转成完整路径, indexOf === 0
    w88975
    w88975
    OP
    Jan 14, 2016
    3
    @chemzqm 目前我也是这种方法检测的,不知道有没有什么隐藏的问题
    taevas
    taevas
    Jan 20, 2016
    4
    如果 路径 `src/js/xxx/../` 允许的话,好像无法使用你这种直接 indexOf === 0 的判断
    w88975
    w88975
    OP
    Jan 20, 2016
    5
    @taevas 目前是不会遇到这种路径的,暂未发现有任何问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   942 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:35 · PVG 04:35 · LAX 12:35 · JFK 15:35
    ♥ Do have faith in what you're doing.