0

I am a little confused with relative path. A simple example “C:\program files\files”. I would say the relative path for the current directory is “.\program files\files”. But I get error that it can’t find. What am I missing?

3 Answers 3

0

Relative Paths

A relative path assumes that the file is on the current server. Using relative paths allows you to construct your site offline and fully test it before uploading it.

For example:

php/webct/itr/index.php

.

Absolute Paths

An absolute path refers to a file on the Internet using its full URL. Absolute paths tell the browser precisely where to go.

For example:

http://www.xuz.com/disted/php/webct/itr/index.php

Absolute paths are easier to use and understand. However, it is not good practice on your own website. For one thing, using relative paths allows you to construct your site offline and fully test it before uploading it. If you were to use absolute paths you would have to change your code before uploading it in order to get it to work. This would also be the case if you ever had to move your site or if you changed domain names.

1
  • How do I determine my current directory? I am working on this Wix project in visual studio. The project solution “My Solution” directory is right under C, and my project My Project is under one of the projects in the solution. So I map my directory like “C:\My Solution” from source control. I need to locate files in one of the folders in My Solution C:\My Solution\A Folder. How do I define the relative path? Is my current directory my C:\My Solution or C:\My Solution\My Project?
    – Jane wang
    Apr 10, 2014 at 18:38
0

A relative path is relative to some other path, usually your current working directory. For example, if you type the MS-DOS command cd \program files on your C: drive, a relative path from there would be files\ or Microsoft\Office. Note the lack of a drive letter or a preceding backslash. A UNIX-like environment would be similar; for example, a relative path to /usr/share/man from /usr would be share/man.

Note that a relative path may not be from your current working/default directory, but rather from some other directory specified as a "default" by a program.

0

It depends from where you are requesting the resource. Let's suppose that you have a script requesting C:\Program Files\Files\targetimage.jpg. Let's suppose that your script is in C:\Program Files directory. Then the path, relative to your script position, would be .\Files\targetimage.jpg.

I hope this was clear enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.