What Is Path //, How Is It Different from /

What is path //, how is it different from /

From Bash FAQ:

E10) Why does `cd //' leave $PWD as `//'?

POSIX.2, in its description of `cd', says that *three* or more leading
slashes may be replaced with a single slash when canonicalizing the
current working directory.

This is, I presume, for historical compatibility. Certain versions of
Unix, and early network file systems, used paths of the form
//hostname/path to access `path' on server `hostname'.

Difference between ./ and ~/

./ means "starting from the current directory". . refers to the current working directory, so something like ./foo.bar would be looking for a file called foo.bar in the current directory. (As a side note, .. means refers to the parent directory of the current directory. So ../foo.bar would be looking for that file one directory above.)

~/ means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/foo.bar would be looking for a file called foo.bar in your home directory, something like /home/totzam/foo.bar. In many web applications, ~/foo.bar would be looking for a file called foo.bar in the web application root, something like /var/http/mywebapp/foo.bar.

Differences between Path and Directory classes and means

Directory is more of a confirmation or assessment of. For example. Does a directory exist providing a string representing the path you are interested in. Create a directory, again, provided a string representing the path.

var myStrPath = @"C:\Users\Public\SomePath\";
if( ! Directory.Exists( myStrPath ))
Directory.Create( myStrPath );

You can also enumerate a given folder looking for more, or cycling through them.

var df = Directory.GetDirectories(@"C:\");
foreach (var oneFolder in df)
MessageBox.Show(oneFolder.ToString());

But you can also use Directory based on RELATIVE Path. For example, where your program is running from, you could do

if( Directory.Exists( "someSubFolderFromWhereRunning" ))

and not worry about fully qualified path.

Path allows you to get or manipulate path/file information, such as a relative path above and you want to know its FULL path even though you dont know where your program is running from. This might be good to look for an expected startup check file in the relative directory the app is running from, or writing files out to same working folder.

You can also get the list of bad characters that are not allowed in a path so you can validate against them in some string.

For each of them, take a look at the "." reference after you do something like

var what = System.IO.Directory. [and look at the intellisense] 
var what2 = System.IO.Path. [intellisense]

And look at the context. It should make more sense to you seeing it with better context.

Path difference between ../ and ./

./ means the current directory

../ means the parent of the current directory, not the root directory

/ is the root directory

myfile.text is in the current directory, as is ./myfile.text

../myfile.text is one level above you and /myfile.text lives in your root directory.

Difference between the path with and without '/'?


os.mkdir('dir_name')  # relative

The first path is relative. The first code line will make a directory "dir_name" in the current working directory. It is relative because the path will change relative to the working directory.

os.mkdir('/dir_name')  # absolute

This second path is absolute. "/" refers the the operating system's root directory. The second code snippet will make a "dir_name" directory in the root directory. The path is absolute because unlike the "current working directory", the root directory will never change.

What is the Difference between \ and / ?

Actually,It's a historical problem.Traditional NT and DOS operating system uses "\" as an internal expression in VFS path.But UNIX-like system uses "/".Also,many complier considers backslash as escape character e.g."\n \r".So to facilitate the porting of different platforms and the communication across computer systems, Windows now also supports splash as a path separator.

What's the difference between path & path.filepath packages in Go


What is the difference?

While functionally similar, path and path/filepath offer differing implementations. Filepath depends on the os package to choose the target runtime's file separators and other differing components when dealing with path strings.

You can look as the os source to see that there are differing implementations for various utility functions. This allows operating system specific details to be abstracted away by the library and helps achieve portability. The path/filepath dependency graph illustrates how the package depends upon the os package. You can compare this with the path dependency graph. I would encourage you to go into the filepath and path source code to observe this relationship.

When do I use each?

You should use filepath when working with files. This ensures your paths will be matched with actual files regardless of the underlying runtime. The path library should be used within models or when paths may be serialized or communicated with other programs. This ensures that a single formatting scheme is used regardless of what platform the programming is running on. Having a consistent format makes reasoning about models more generic and easier to understand.

Difference between \\ and / when working with path directories

There's nothing wrong with using / on systems that support it. In fact, on UNIX systems it's the only thing that works.

Windows supports both / and \ as path separator in most situations.

Note that a platform agnostic option is available in the form of std::filesystem::path.

sys.path vs. $PATH

you can read environment variables accessing to the os.environdictionary

import os

my_path = os.environ['PATH']

about searching where a Package is installed, it depends if is installed in PATH



Related Topics



Leave a reply



Submit