Question:
When do i use ../ and ./ in a source path of a file , in writing a script?
babu333
2012-06-17 00:13:21 UTC
For example if my jquery file and index.php file in a same folder i can just simply write in index.php.
In which situation do i use ../ and ./ . Please give a detail answer with example.
Without example it will be hard to understand for me.
Thank you.
Three answers:
anonymous
2012-06-17 00:38:26 UTC
../ means the folder above the current path, and ./ (in javascript, but slightly different in other languages) means the same folder as the MAIN script that first ran (i.e. index.html, not something that was called from index.html).



For example, if you only used...



src="jquery.js"



...you are telling the script you want to access the file in the same folder as the script that is running right now, so this will change based on where your calling script is. What this means is, say you write that line in c:\www\index.html. Your script will expect to find jquery.js in c:\www\jquery.js. But if index.html calls a script myscript.js in the scripts folder, and THEN myscript.js calls jquery.js, your script will expect to find jquery.js in c:\www\scripts\jquery.js. Adding nothing just means, "whatever the current folder is".



if you used...



src="../jquery.js"



...you are telling the script you want to access the file in the folder ABOVE the current script. So it would expect to find it in c:\jquery.js



if you used...



src="./jquery.js"



...you are telling the script you want to access the script in the same folder as the ORIGINAL calling script, not necessarily the script that wrote that line. For example if index.html gets called and it's in c:\www\index.html, then that index.html file calls /scripts/mootools.js, and mootools.js calls "./jquery.js", jquery.js will be expected to be in c:\www\jquery.js (because that's where the original script that ran was), NOT c:\www\scripts\jquery.js



It might sound confusing but it's not: no dots/slashes means the path = the current running folder. 1 slash means the root folder, 1 dot and 1 slash means the original calling folder, and 2 dots and 1 slash means the parent to the original calling folder.
K-SiS
2012-06-17 00:22:58 UTC
currunt directory is reffered by . and parent is reffeded by ..



This is used for relative addressing since websites are usually virtually hosted & true path is unavailable to us. So relative path is the solution. that is the reason why ./ is used.

If images are stored in image folder it is reffered as ./image/FileName.jpg
ferrigno
2016-10-28 13:25:47 UTC
best undertaking you're able to do earlier attempting to restoration your workstation -- back UP all your significant records / pictures or very own video clips. then you definately circulate approximately and run a virulent disease test & verify if it fixes the priority. additionally, do as others have already pronounced. reliable luck S


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...