douhuocuo9012 2016-08-22 19:41
浏览 9
已采纳

对于在php中更改文件夹,/../。/。/和../之间有什么区别?

For changing file folders what is the difference between

/../
./../
../ ?

Some includes won't work unless it is include "/../filename.php"; while others will work just fine with include "../filename.php;".

  • 写回答

3条回答 默认 最新

  • dongxie2756 2016-08-22 19:51
    关注

    Pathing 101:

    Every running process has a "working directory". This is where any "relative" paths in file operations will be based from.

    ./          - current directory (the "working" directory)
    ../         - parent directory
    ../..       - grandparent directory
    ../foo      - brother/sister directory "foo"
    ../../foo   - uncle/aunt directory "foo"
    

    There are also ABSOLUTE paths, which start at the ultimate ancestor of all directories - the root of the file system. On Unix-ish systems, that's /, on Windows systems, that'd be a drive letter, e.g. C:\

    /            - ultimate starting directory - root of file system
    /foo         - immediate child directory
    /foo/bar     - grandchild directory
    /foo/bar/baz - great-grandchild directory.
    

    Combining these:

    absolute+relative:

    /foo/bar/../baz
    
       1. `/`     - start at root /
       2. `/foo`  - descend into 'foo' (now at `/foo`)
       3. `/bar`  - descent into 'bar' (now at `/foo/bar`)
       4. '../`   - go back a level  (back at `/foo`)
       5  `/baz   - descend into  'baz` (now at `/foo/baz`)
    

    relative:

    ../foo/bar/../baz
    
      1. Start in current directory `./`
      2. `../` - ascend to parent (now at `../`)
      3. `foo/` - descend into sibling `foo` (now at `../foo`)
      4. `bar/` - descend into niece/nephew `bar` (now at `../foo/bar`)
      5. `../` - ascend back to sibling foo (now at `../foo`)
      6. `baz/` - descend into niece/nephew 'bar' (now at `../foo/baz`)
    

    Basically, ANY path which starts with / or c:\ is an absolute path, and any path starting with a . is a relative one. EVERY directory contains . and .., which are simply pointers to itself (.), and its parent (..). The parent is there so you don't need to know the name of your ancestor directory, you just need to know ...

    Since directories contain a reference to themselves, something like ./././././. is simply a very redundant way of saying "in the current directory".

    Therefore ../foo/./bar is no different than ../foo/bar, because the ., being where it is, simply means "stay in the same place".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错