Questions tagged [relative-path]

Relative-paths are URI or directory links to resources that refer to a location relative to the current path.

A relative path references a resource in relation to a current path or directory; its opposite is an absolute path. Web pages frequently make use of relative paths to refer to resources like images and scripts. The advantage of using a relative path is that it remains valid when the host name or root path changes.

As an example, consider a website located at the URL:

http://www.hostname.com/site/page.html

If the page wants to reference an image located at:

http://www.hostname.com/site/images/image.jpg

It could simply make reference to the relative path images/image.jpg.

2470 questions
59
votes
5 answers

How to require PHP files relatively (at different directory levels)?

I have the following file structure: rootDIR dir1 subdir1 file0.php file1.php dir2 file2.php file3.php file4.php file1.php requires file3.php and file4.php from dir2 like this…
Boris D. Teoharov
  • 2,319
  • 4
  • 30
  • 49
57
votes
5 answers

How to Relocate Visual Studio project (.sln) file

I would like to move the Visual Studio solution (myProject.sln) file into a folder. The problem with doing this is that all the relative paths in the project will break, how can you relocate the project without updating all relative paths inside the…
Brock Woolf
  • 46,656
  • 50
  • 121
  • 144
57
votes
6 answers

How do relative file paths work in Eclipse?

So my 2009 new years resolution is to learn Java. I recently acquired "Java for Dummies" and have been following along with the demo code in the book by re-writing it using Eclipse. Anyway, every example in the book that uses a relative path does…
PHLAK
  • 22,023
  • 18
  • 49
  • 52
57
votes
7 answers

How does Java resolve a relative path in new File()?

I am trying to understand the way Java resolves relative path in while creating a File object. OS used: Windows For the below snippet, I am getting an IOException as it cannot find the path: @Test public void testPathConversion() { File f =…
Eswar
  • 1,045
  • 1
  • 8
  • 11
56
votes
2 answers

How to use a path relative to project root to H2 db-file configuration with Play Framework 2.4?

We're developing a Play 2.4 application (Java API). For dev purposes, we'd like to use a persistent H2 database with DB file path relative to the project root directory. In How to use a persistent H2 database in the Play Framework instead of…
Touko
  • 11,359
  • 16
  • 75
  • 105
55
votes
3 answers

Slash (/) vs tilde slash (~/) in style sheet path

ASP.NET offers two ways to specify paths for style sheets: (this is working) (this is not working) How are these…
Kyasa Madhavi
  • 705
  • 1
  • 6
  • 10
51
votes
4 answers

Relative import from parent directory

How does one do a relative import from a parent directory? From meme/cmd/meme: import "../../../meme" This gives an ambiguous error: matt@stanley:~/gopath/src/bitbucket.org/anacrolix/meme/cmd/meme$ go get…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
49
votes
8 answers

How to use fstream objects with relative path?

Do I always have to specify absolute path for objects instantiated from std::fstream class? In other words, is there a way to specify just relative path to them such as project path?
user336359
  • 1,244
  • 1
  • 11
  • 18
49
votes
11 answers

Getting relative path from absolute path in PHP

I noticed some similar questions about this problem when I typed the title, but they seem not be in PHP. So what's the solution to it with a PHP function? To be specified. $a="/home/apache/a/a.php"; $b="/home/root/b/b.php"; $relpath =…
Young
  • 7,986
  • 7
  • 43
  • 64
49
votes
3 answers

How to force an HTML link to be absolute?

In my website, users can put an URL in their profile. This URL can be http://www.google.com or www.google.com or google.com. If I just insert in my PHP code $url, the link is not always absolute. How can I force the a tag to be…
Arnaud
  • 4,884
  • 17
  • 54
  • 85
47
votes
8 answers

PHP absolute path to root

I can't believe PHP doesn't have an easy solution for this simple matter. ASP.NET has a ~ sign that takes care of this issue and starts everything from the root level. Here's my problem: localhost/MySite -->Admin -- Edit.php -->Class …
SZT
  • 1,771
  • 4
  • 26
  • 53
46
votes
3 answers

MVC Bundling and CSS relative URLs

MVC's bundling is returning the wrong URL in CSS images when using CssRewriteUrlTransform: I have an intranet application whose URL is, for example: http://usid01-srv002/MyApplication. It's in IIS's "Default Web Site". Which has the following in…
44
votes
1 answer

Relative URLs and trailing slashes

I've looked around the web for this before, and I suspect the answer is "you can't", but since I've not yet found an answer which is that definitive, I think it's worth asking here. The closest I've found touching on the problem is The mystery of…
Adam Prescott
  • 1,145
  • 2
  • 11
  • 17
44
votes
1 answer

Codeigniter - dynamically getting relative/absolute path outside of application folder

I am attempting to have a temporary cache folder of sorts just outside of and at the same level as the application folder. This is for storing images for a couple moments before moving them off-site. I am trying to get a user's Facebook profile…
chris
  • 36,115
  • 52
  • 143
  • 252
44
votes
1 answer

Ruby: How to calculate a path relative to another one?

Let's say I know the absolute path that I am starting from and the absolute path that I am trying to get to: first = '/first/path' second = '/second/path' Now I want to figure out how to construct a path that is relative to the first. For…
Andrew
  • 227,796
  • 193
  • 515
  • 708