关于文件路径
文件的路径有相对路径和绝对路径。但有些文章有时让我感到困惑:
/a/b/c.php //relative document root
./a/b/c.php //what does this mean? equals to '/a/b/c.php' or a/b/c.php?
a/b/c.php //relative to current directory
../a/b/c.php //parent folder relative to current directory
/../a/b/c.php //what does this mean? parent folder of document root?
还有其他写法吗?
谢谢。
There are relative path and absolute path of the a file. But some of the writings confuse me sometimes:
/a/b/c.php //relative document root
./a/b/c.php //what does this mean? equals to '/a/b/c.php' or a/b/c.php?
a/b/c.php //relative to current directory
../a/b/c.php //parent folder relative to current directory
/../a/b/c.php //what does this mean? parent folder of document root?
Are there other ways of writing this?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些基本的目录符号:
.
(点)是当前目录..
(双点)是当前目录的父目录~(波形符)是您的主目录。
/
(斜杠)如果它出现在第一个字符,通常称为根目录。这些都来自linux/unix术语(这里是CMIIW)。
现在,让我们看一下实现:
/home/username/
上./wwwroot/somedir/
=>/home/用户名/wwwroot/somedir/
../wwwroot/somedir/
=>/home/wwwroot/somedir/
/../wwwroot/somedir/
=>/wwwroot/somedir
您可能会对示例 #3 感到困惑。如果在路径信息前面加上
/
,则表示您位于根目录。因此,如果你写/../somedir/
则意味着你指向 /somedir/。为什么?因为根目录没有父目录。Here's some basic directory symbol for you:
.
(dot) is your current directory..
(double-dot) is the parent of your current directory~
(tilde) is your home directory./
(slash) if it present at first character, it usually is called root directory.These all came from linux / unix terminology (CMIIW here).
Now, let's take a look at the implementation:
/home/username/
./wwwroot/somedir/
=>/home/username/wwwroot/somedir/
../wwwroot/somedir/
=>/home/wwwroot/somedir/
/../wwwroot/somedir/
=>/wwwroot/somedir
You might get confused on example #3. If you put
/
in front of path info, it mean you are at the root directory. Therefore, if you write/../somedir/
it mean, you are pointing to /somedir/. Why? because root directory doesn't have parent.。 = 当前目录。因此
./a/b/c.php
相当于a/b/c.php
。/../a/b/c.php
表示先到根目录,然后上一层,再到目录a
,再到目录b
,然后是c.php
。. = current directory. So
./a/b/c.php
would be equivalent toa/b/c.php
./../a/b/c.php
means go to the root directory, then up one, then directorya
, then directoryb
, thenc.php
.