22

I am trying to code my Home button. Is there a way to just climb back up the file structure, instead of using the absolute path like I have below.

I have a file index.html that I have at C:\Users\Randy\Documents\XML\

Heres my code:

<a id="my-family" href="C:\Users\Randy\Documents\XML\index.html">Home</a> 

Heres where I am trying to come from: C:\Users\Randy\Documents\XML\project\xml

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
user770022
  • 2,899
  • 19
  • 52
  • 79

6 Answers6

40

to go two level up use "../../" and your normal url from two level up folder.

"../" in the path is used to go one level up. But, it can be used for more times, to go more levels up.

an example:

| HOME <br> 
+- image.jpg<br> 
|_
  |
  +- CONFIG<br>  
     |
     + PICTURE_CONFIG
       | 
       +- myfile.html

myfile.html contains:

<img src="../../image.jpg" />

the second"../" goes from PICTURE_CONFIG to CONFIG folder
the first "../"goes from CONFIG to HOME folder
"image.jpg" searches in HOME folder for the file "image.jpg"

Tudor
  • 980
  • 8
  • 10
26

You can use ../index.html to refer to index.html in the parent directory.

Shi
  • 4,178
  • 1
  • 26
  • 31
  • 1
    Thanks but that didnt work. I get page cannot be displayed, and my guess is it still doesnt find the index.html – user770022 Aug 13 '11 at 16:32
  • 7
    I was trying to go back up 2 directorys so I needed ../../ Thanks for your help. – user770022 Aug 13 '11 at 16:36
  • 4
    If you are at `C:\Users\Randy\Documents\XML\project\xml` and want to go to `C:\Users\Randy\Documents\XML\index.html` you of course need to go up two levels: `..\..\index.html`. – Shi Aug 13 '11 at 16:38
4

On Windows OS, the forward-slash (/) wasn't working, so I switched to back-slash (\) and that fixed it. For example, try using the following:

"..\..\index.html"
Leland Hepworth
  • 876
  • 9
  • 16
2
  1. <img src="picture.jpg"> WHEN picture.jpg is located in the same folder as the current page

  2. <img src="images/picture.jpg"> WHEN picture.jpg is located in the images folder located in the current folder

  3. <img src="/images/picture.jpg"> WHEN picture.jpg is located in the images folder located at the root of the current web

  4. <img src="../picture.jpg"> WHEN picture.jpg is located in the folder one level up from the current folder

    1. <img src="../../picture.jpg"> WHEN picture.jpg is located in the folder two levels up from the current folder

Hope this example help :)

Source: https://www.w3schools.com/html/html_filepaths.asp

Edd C.
  • 21
  • 3
2

I'm not sure exactly what you're asking, but in relative paths, ../ is 'up one level'.

So, ../index.html would take you to the index of the next directory up. Hope that helps.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Dennis
  • 482
  • 7
  • 17
-2

In IIS10 below is my observation and both works fine:

single Dot will take you one folder above
img src="./images/picture.jpg"

Double Dot will take you two folders above
img src="../images/picture.jpg"

Adi
  • 27
  • 4
  • This question was asked almost 10 years ago, and had been answered by many people, and your answer brings nothing new to this discussion. Could you perhaps edit to provide new information? If you can't provide any, this answer is pointless. – VirxEC Mar 10 '21 at 13:11
  • I had faced this issue myself and got the solution myself too, none of the solutions above worked for me except mine, if you had really went thru all the solutions, you would have realized that my solution is different than any other solutions above. Even if the question was old I posted an answer so it might help atleast one person, I just cant help when your whole intention is just to down vote an answer!!! – Adi Mar 23 '21 at 03:36
  • From what I can read, your answer is the same as https://stackoverflow.com/a/44460141/10930209 , just lower quality – VirxEC Mar 25 '21 at 19:52
  • 2
    Also confusing, as "single Dot will take you one folder above" is incorrect - a single dot refers to the current folder. – VirxEC Mar 25 '21 at 19:53