about the file path - directory

There are relative path and absolute path of the a file. But some of the writings confuse me sometimes:
/a/b/c.php //relative document root
./a/b/c.php //what does this mean? equals to '/a/b/c.php' or a/b/c.php?
a/b/c.php //relative to current directory
../a/b/c.php //parent folder relative to current directory
/../a/b/c.php //what does this mean? parent folder of document root?
Are there other ways of writing this?
Thank you.

Here's some basic directory symbol for you:
. (dot) is your current directory
.. (double-dot) is the parent of your current directory
~ (tilde) is your home directory.
/ (slash) if it present at first character, it usually is called root directory.
These all came from linux / unix terminology (CMIIW here).
Now, let's take a look at the implementation:
Let's say, you are on /home/username/
if you write something like this, the result is:
./wwwroot/somedir/ => /home/username/wwwroot/somedir/
../wwwroot/somedir/ => /home/wwwroot/somedir/
/../wwwroot/somedir/ => /wwwroot/somedir
You might get confused on example #3. If you put / in front of path info, it mean you are at the root directory. Therefore, if you write /../somedir/ it mean, you are pointing to /somedir/. Why? because root directory doesn't have parent.

. = current directory. So ./a/b/c.php would be equivalent to a/b/c.php.
/../a/b/c.php means go to the root directory, then up one, then directory a, then directory b, then c.php.

Related

How to change to the next above directory

I really would like to know how to change directory to the next file, using 2 dots (/..).
I can go back to previous directory but how to do something like that to go to the next directory WITHOUT THE NAME OF THE FILE PLEASE!
I know it is possbile with the name of the folder but my answer is different, please let me know.
What O.S are you using? In linux ubuntu/Debian distributions (and probably in windows, not sure), you can enter the first child directory by simply typingcd */, this will change your current directory to the first child directory available in alphabetical order, example:
-/home
-alan
-desktop
-music
-alex
-documents
-pictures
-lisa
Assuming your in /home, if you write cd */ in the terminal you will be in /home/alan, because -alan is the first folder/directory available.

UNIX paths -- what do ., ~, .. prefixes mean?

/home/ise is my shell-base folder.
What are the differnces between those lines ?
Thanks.
/home/ise
./home/ise
~/home/ise
../home/ise
/home/ise # absolute path (often "/" is the root of your hard drive)
./home/ise # relative to current directory
~/home/ise # relative to the current users home directory
../home/ise # relative to the current directory's parent folder
/home/ise - specifies path from disk
./home/ise - same as above, the . indicates current directory
~/home/ise - ~ indicates from home directory
../home/ise - .. specifies parent directory

Absolute path of the project root directory in Julia

The project root directory of a file located in PROJECT_ROOT/lib/code.jl can be accessed with this code:
root = dirname(dirname(#__FILE__))
Using dirname() twice seems pretty ugly. Is there a better way to do this? With Ruby, I would use this code:
root = File.expand_path('../', File.dirname(__FILE__))
Thanks for making me find out about:
"/"*relpath((#__FILE__)*"/../..","/")
According to ?relpath, it gives a path from the location of the second argument in the file-system, to the first argument. Is this better than the double dirname solution?
A variant of the same niceness is:
normpath(joinpath(#__FILE__,"..",".."))
Closest to Ruby equivalent might be:
realpath(dirname(#__FILE__)*"/..")
I like to use
module Foo
const PROJECT_ROOT = pkgdir(Foo)
end # module
where the definition of PROJECT_ROOT can also be replaced by
const PROJECT_ROOT = dirname(dirname(pathof(Foo)))
Or, you could use
const PROJECT_ROOT = pkdir(#__MODULE__)
I just use
const PROJECT_ROOT = #__DIR__
from inside my _init.jl file, which resides in the project root directory (next to the src directory) and gives you a canonical path.
I get my _init.jl files automatically executed when opening a Julia session from inside that directories by having
isfile("_init.jl") && include(joinpath(pwd(), "_init.jl"))
in my ~/.julia/config/startup.jl file. If you started Julia elsewhere, you have to include("_init.jl") it (or respective relative path) manually.

What does .. at the start of filepath do?

What does ..\ at the start of a file path do?
Example: The following file is referenced in the directory
\work\QA\Reports\TimeOff.rpt
What is the difference between referencing the file path as \work\QA\Reports\TimeOff.rpt and referencing the file path as ..\work\QA\Reports\TimeOff.rpt?
it's the difference between relative and absolute path referencing.
\work\QA\Reports\TimeOff.rpt
starts with a (back)slash "\" (or "/" in unix if it matters), so it's indicating "Start at the root, or top most level directory".
Then navigate down.
It's an Absolute path reference. It doesn't matter where you are, you will always end up pointing to the same file/location.
.\work\QA\Reports\TimeOff.rpt
however, begins with "." Which is Relative path reference. It says to "start where you currently are". so if you were already in folder: \my\home\directory
then you'll end up navigating to:
\my\home\directory\work\QA\Reports\TimeOff.rpt
".." is a reference to go one level up ... but again "relative path".
so:
..\work\QA\Reports\TimeOff.rpt
if you were in \my\home\directory
you'd end up here:
\my\home\work\QA\Reports\TimeOff.rpt
Since it backs up one level ("\directory\") ..and goes from there.
Hope that makes sense ;)
.. refers to the parent directory, the directory one level up from the current directory. Additionally, . refers to the current directory.
Say you're in directory \a\b\c\. You want to access file \a\b\c\d. You can access that file with just d or .\d or \a\b\c\d. Say you now want file \a\b\x. You can access that as ..\x or the full absolute path. You can, of course, chain . and .., like ..\.\..\y.
Paths starting with \ are absolute (or <drive letter>:\); they refer to the same file every time and don't depend on the current directory. Other paths are relative, the file they refer to changes with the current directory.
It means go to parent folder first and then look for the path specified.
so it is basically the same when you do cd .. in command line.
The difference between \work\QA\Reports\TimeOff.rpt and ..\work\QA\Reports\TimeOff.rpt is thet if you're in \a\b folder, first one will match \a\b\work\QA\Reports\TimeOff.rpt and second one a\work\QA\Reports\TimeOff.rpt.

Server.MapPath does not like ~/ and ./

I am using the following code to try and find a file contained in another directory from my code file.
Set fi=fs.OpenTextFile(Server.MapPath("~/counter/counter.txt"), 1)
I have also tried.
Set fi=fs.OpenTextFile(Server.MapPath("./root/folder1/counter/counter.txt"), 1)
In either case this should get me back to the counter.txt file. From what I understand ~/ moves up 1 directory and ./ moves up to the root directory.
Both times however I receive an error saying an invalid character has been used. When removing these I get a different error saying the path cannot be found (Which I would expect because it is not a valid path without moving up 1 directory).
What are the valid characters to do the following in VBscript:
move up a single directory?
move up to the root directory?
Thanks for the help
A few things:
The tilde character "~" is not valid here.
The single period character "." is for specifying the current directory/folder.
A set of period characters ".." is for specifying the parent directory/folder. For example, to refer to a file found in the parent of the current directory, you might use:
Server.MapPath("../counter.txt")
You can chain these to walk up more than a single parent path. To refer to a file found three directories above the current, you might use:
Server.MapPath("../../../counter.txt")
The documentation on MSDN for the MapPath function outlines this. Pay attention to the caution listed here about enabling parent paths if you want to be able to refer to relative paths above the current directory. If you get an error when trying to refer to a parent path, then you do not have parent paths enabled.

Resources