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

/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

Related

File Should Exist is not recognizing filepath

I'm using the File Should Exist keyword to check for an existing file in a List.
This is the high-level format:
Variables:
#{Files} /Desktop/Other/scooby.txt
... /Desktop/DummyFiles/daffy.txt
... %{CURDIR}/mickey.txt
Test Case:
Given File Should Exist ${Files[0]}
[...]
Output:
Setup failed:
Path '/Desktop/Other/scooby.txt' does not exist.
I'm not sure why this happens. The file name and filepath are correct. I also tried a bunch of different combinations (I copied the file over to the subdirectory this script is running from but that also doesn't work). I tried making the filepath a scalar variable instead of a List/array. Adding ".." in front of the file path doesn't work either. I've looked into "Glob pattern" but I don't think that's the issue either.
Always use absolute paths if in doubt. For example - /Desktop/Other/scooby.txt Does not point to any "meaningful" path even on windows because its lacking the the drive. On windows, using C:/Users/$yourlocalusername/Desktop/Other/scooby.txt might be working (replace $yourlocalusername with correct value)
Relying on relative paths (like in your example, 2 first ones are relative even thought you start with /, because in windows you still have a drive at the start) - you will need to ensure that working directory is set to a specific directory before you run your suite. Now, if you run your suite via IDE, current working directory might not be what you expect it to be so before you are familiar with how relative & absolute paths work - prefer to use absolute paths. See https://www.computerhope.com/issues/ch001708.htm - maybe that will clear out your issue.
You can either use ${CURDIR} or do not start the relative path with '/'.
I guess when starting with '/' , RF does not take this as relative path input and try to map the address from root directory i.e. C:
In below example, I have demonstrated both the approach, and it works fine for me.
*** Settings ***
Library OperatingSystem
Documentation Demonstrating File Exist keywords
*** Variables ***
#{Files} Data/VariableData/ConditionalFlows.robot
... Data/VariableData/testdata.robot
#{Files2} ${CURDIR}/Data/VariableData/ConditionalFlows.robot
... ${CURDIR}/Data/VariableData/testdata.robot
*** Test Cases ***
TS002-Check For File Existence
[Documentation] File exists
${File} File Should Exist ${Files}[0]
${File} File Should Exist ${Files2}[0]

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.

about the file path

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.

Absolute path with disk name (C:\\) to relative path (~/)

Any built in way to get virtual / relative path or URL from absolute path containing disk name such as?
Or how to convert this :
C:\\ProjectRoot\\Somedir\\demo.text
to this
~/Somedir/demo.text
Thanks.
Request.PhysicalApplicationPath will give you the physical root of your virtual directory.
So in your case if your virtual directory was at c:\projectroot, then you'd want ~/somedir/demo.txt right?
So if you did a string replace on the file path, replacing Request.PhysicalApplicationPath into a tilde character, along with swapping \ for / , then you'd get what you needed.

Resources