I am new to programming, so I am confused. I know that relative path is a way to specify the location of a directory relative to another directory.
But I don't understand why do I need relative path. Could you please give me an example?
why do I need relative path
So that when you ship your code, you don't have to worry about where the user will put that code, while using a path to some resource.
You can use a path relative to the project root, which will be same regardless of where the project is.
Absolute path is the full directory path .
Relative path is relative to the directory you are in, so if you are in the above directory, then if you reference file test.txt as relative, it assumes the same directory you are in. When you do ../ then it goes back one directory.
Suppose you are in a directory whose path is k... In this directory there is a file named a.txt. Now
the absolute path is C:\A\B\a.txt
the relative path is a.txt (as you are in the same directory).
Why you need a relative path
You need a relative path so that in your code you can use any file without depending on the path set by user. For example in your code you need to access a file. If you use absolute path then the path will change depending on the location where the user will set it.
But if you use relative path then the path will be always same as it will always be in your project folder. (or a fixed hiararchy)
Great question. I've noticed relative paths are extremely helpful when dealing with larger sites that have a test or staging area, then the actual live site.
For example, say you have TEST.MYSITE.COM which in turn gets pushed out to WWW.MYSITE.COM. In this example, relative links do not need to be updated because you test the file, the push live when it meets your expectations.
Lets say you have an html file that references TEST.MYSITE.COM/MYFOLDER/MYIMAGE.JPG and you would like to update this image. After the image has been corrected, if you are not using relative links, you would then need to change the image name on the html file from "TEST.MYSITE.COM/MYFOLDER/MYIMAGE.JPG" to "WWW.MYSITE.COM/MYFOLDER/MYIMAGE.JPG".
If one was using the relative link "/MYFOLDER/MYIMAGE.JPG" this would not need to get updated. You could only imagine how this example would get multiplied throughout the site, which would then become a tedious process.
Relative links help avoid this. Hopefully this makes some sense. It sounds like you know what they are, this was just attempting to answer "why do I need relative path[s]".
Related
In a UWP app using cppwinrt I want to use WebView to display contents of a book kept in the Assets folder. I read that it is necessary to reference an html asset this way for use as a Uri argument to the Navigate method in web view:
TheWebView.Navigate(Uri(L"ms-appx-web:///SampleBook/PageOne.html"));
This produces an empty view, while
TheWebView.Navigate(Uri(L"ms-appx:///SampleBook/PageOne.html"));
crashes. Msdn says that for files "that will be loaded into the web compartment" one must use ms-appx-web, and I've seen mention that this is a security issue. But does that mean the files are in a special location within the project - i.e. not merely in the Assets folder - or does it only mean that the path must begin with ms-appx-web independent of the file's location? "Web compartment" is not explained but seems to be not a location but rather a classification of the type of resource. At any rate, neither of the above approaches works, so I'm curious to know the recommended way to store and access a collection of html files in the package. In the assets folder? A special folder within assets? In Solution Explorer the html file is listed, "content" is True, and the file is Included In Project. Thanks.
My mistake: ms-appx-web does not point to the assets folder, but to its parent. The correct path for content of this type would be ms-appx-web///Assets/SampleBook/PageOne.html. The reference to material to be "loaded to the web compartment" apparently is just a way of saying: stuff to be loaded with WebViewer.
I was using the basePath property but the result of the build is not what I expected.
This is my profile based on one of the basic examples
dependencies= {
basePath:"../..",
releaseDir: "./TESTING"
};
I’m executing the build with the following command (shows the folder where the batch file is located and the full path to the profile)
C:\Users\me\Downloads\dojo-release-1.10.8-src\util\buildscripts>build.bat --profile "C:\Users\me\Downloads\dojo-release-1.10.8-src\util\buildscripts\profiles\test.profile.js" --release
According to the documentation
https://dojotoolkit.org/reference-guide/1.10/build/buildSystem.html#id1
“If the profile contains the property basePath and the value of that
property is a relative path, then the build system will automatically
resolve that path with respect to the directory in which the profile
resources resides–not the current working directory”
“Relative destination paths are computed with respect to the profile
property releaseDir, optionally with a concatenated path segment given
by profile property releaseName. If releaseDir is relative, then it is
taken to be relative to basePath”
So if I specify the basePath as I did, I would have expected it to place itself relative to the profile location that I specified, so that is
Profile location
C:\Users\me\Downloads\dojo-release-1.10.8-src\util\buildscripts\profiles\test.profile.js
basePath location relative to profile (go back two levels)
C:\Users\me\Downloads\dojo-release-1.10.8-src\util\
So going back two levels means placing myself in the ‘util’ folder
So I would expect the release dir to be written in the util folder as well.
However it is being written to the
buildscripts folder inside util.
On a second test I made the profile like this
dependencies= {
basePath:"../..",
releaseDir: "../TESTING"
};
And my release directory was written to the util folder. Which means the basePath I specified is actually pointing to the buildscripts folder but there is no subfolder deep enough to get to it using …/… if …/… means going back two levels.
So either I misunderstand what …/… means or something else is going on.
Can someone please explain how paths work in the build system when you specify a basePath?
Thanks
I need some help for my OS X program.
I need the URL of a file inside the supporting files.
I have an array in which I save URLs from images and add them to a table view and if no images are chosen I want to add a question mark image (it is called "bild.jpg")
This bild.jpg is inside the supporting files but for later use I can't just save the name of the image because the array stores also URLs.
I need to have the URL of that image in the supporting file because it's easier to use the array for image initialization.
Is there a function to get the path or is there a standard path to the supporting files? I already search on the net but couldn't find anything that could help.
You seem to be talking about the application bundle and its resources directory rather than, say, a subdirectory in ~/Library/Application Support/..., in which case you probably want something like:
[[NSBundle mainBundle] URLForResource:#"bild" withExtension:#"jpg"]
(See the documentation for NSBundle.)
I have a path problem when using loadImage() and loadStrings() in Processingjs. I would like to have my sketches and their associated files (images, text files) in one place and to be able to call them from another on my site.
For example, I am trying to run a Processingjs sketch located at
www.example.com/sketches/mysketch.pde from the page www.example.com. This works fine when there are no external files.
Alas the problem starts when I need to use loadImage() and loadStrings() to look for images and texts to load. It defaults to www.example.com/image.jpg and not to the sketch location, www.example.com/sketches/image.jpg.
The need for #pjs preload makes matters worse.
Without moving the files and without hardcoding, is there a way to
tell Processingjs to look for the files to load in the same folder as
the .pde and not the .html?
I hope this is clear. Any help would be appreciated!
Short answer: no.
Even native Processing won't behave the way you want in this sense, because you'll be executing your sketch from [...]/sketches/ and any resource call is local to that directory.
Similarly, with processing.js your resources are located relative to the "directory" you're in, which for www.example.com/ is just the base dir. What you can do, however, is place your .pde file in the same dir as your .html file, or vice versa.
#pjs preload is necessary to effect "immediate" file loading. If you don't preload it, your sketch will have to deal with asynchronous load instructions. Quite literally, loadImage without a preload directive behaves the same as requestImage (http://processing.org/reference/requestImage_.html)
Few facts first:
1. I can only use ActionScript 2.
2. All files are within the same domain (i.e "http://www.example.com").
I have a loader SWF which acts as a selection tool ("auto_magic.swf") located at "/" in the website (the root folder).
A User selects the tool he needs (it's a mechanical diagnostic system) and the main movie loads it (currently I use loadMovie() - suggest else if needed).
That tool is located at "/tools/[tools_name]/tool_main.swf".
Now, the "tool_main.swf" is loading just fine.
The problem is that "tool_main.swf" needs to load other files located in its folder, so for example it tries to load "config.xml", BUT Flash isn't looking for "config.xml" in the tool's dedicated folder - instead it's looking for this file at the root folder "/" where "auto_magic.swf" is located, probably because the movie's main swf is coming from there.
To make it even worst I cannot modify the tool's SWF ("tool_main.swf") because it's coming from a third party.
Is there any solution? As far as I see this I need one of these solutions;
1. Be able to set the base url of the loaded swf.
2. *Change* the whole movie's base url at run-time because it needs to load several tools from different folders.
Trying to solve this for several good hours. Help will be highly appriciated!
relative paths are always relative to where the main swf exists. so as your load chain expands, '/' always refers to the location of the Main.swf.
in AS2, you can inspect a swfs _url property to determine its fully qualified url location, and determine its parent folder.
In the AS2 child swf, you can use this:
var myfolder = this._url.slice(0, this._url.lastIndexOf('/') + 1);
and then use that to load in further assets relative to itself.
hope that helps.