What is the difference between "C:\Android\sdk" and "C:\Android\sdk\" when adding path in environment variables or any other place?
There is no difference. A trailing backslash (or slash in the case of UNIX) is ignored by the operating system. There are only two uses that I know of. First, dealing with broken programs that incorrectly assume a trailing slash/backslash is present when concatenating the value to another relative path. Second, a very small number of commands (e.g., scp) might assign special meaning to a trailing path delimiter.
Related
I was teaching an online course and a student asked me why R only uses / and not \ in file paths when using read.csv and other related functions. I tried looking at the documentation but it didn’t really mention anything about it. Never really thought about it because I use a Mac, and the default in Macs is \, but not so in Windows machines.
I’m not trained in computer science so I was left a bit stumped to answer the question a I’m afraid. Students always ask the darnest things!
Interesting question.
First off, the "forward slash" / is actually more common as it used by Unix, Linux, and macOS.
Second, the "backward slash" \ is actually somewhat painful as it is also an escape character. So whenever you want one, you need to type two in string: "C:\\TEMP".
Third, R on Windows knows this and helps! So you can you use a forward slash whereever you would use a backward slash: "C:/TEMP" works the same!
Fourth, you can have R compute the path for you and it will use use the separator: file.path("some", "dir").
So the short answer: R uses both on Windows and lets you pick whichever you find easier. But remember to use two backward slashes (unless you use the very new R 4.0.0 feature on raw strings which I'll skip for now).
(Note: backslashes as directory folder separators on Macs is a recent innovation.See History of Mac folder separators
I think if you review the history (or look it up if you were not there when it occurred as I was) you will find that Unix (which Linux copied completely) got there first. It preceded either MS-DOS or Macs or last of all Windows. R is a work-alike clone of S which was developed like Unix at Bell Labs.
Mac originally used colons (:) as folder separators (and still won't accept them in file names) and converted to slashes sometime during its long transition to BSD Unix which it licensed from ATT.
Shouldn't the question be: why Microsoft chose to use a backslash?
It seems that the output are the same when I echoed it.
I also tested other commands such as open, but the results from both are the same.
In traditional sh-style pattern matching, * matches zero or more characters in a component of the file name, so there is no difference between *, **, and ***, either on its own or as part of a larger pattern.
However, there are globbing syntaxes that assign a distinct meaning to **. Pattern matching implemented by the Z shell, for example, expands x/**/y to all file names beginning with x/ and ending in /y regardless of how many directories are in between, thus matching all of x/y, x/subdir/y, x/subdir1/subdir2/y, etc. This syntax was later implemented by bash, although only enabled when the globstar configuration option is set by the user.
When I organize my directories I often want certain directories to stand out in ls. For example, I will sometimes have a directory called #backup# and this will end up in the top of the list of directories, rather than in between all directories starting in "b". Sometimes, though, I want a directory to be at the bottom of the list, but I haven't found any symbol that achieves this. (The closest I've come is z#name#z, but this doesn't quite cut it.) So: Are there any symbols that come after all letters in Unix's alphabetical sorting?
You can use any (e.g. ASCII or Unicode [it depends upon your encoding and localization]) character except NULL (used as the ending of filepath) and / (used to separate directories in file path). See path_resolution(7). You might consider using ~ because several utilities (see indent(1), mv(1)....) adopt the convention to backup file /home/nag/foo as /home/nag/foo~. AFAIK #foo# could be used by emacs to backup temporarily an edited (but unsaved) file foo.
Is there any special character that cannot be a part of the path in Windows or Unix that I can use it as a separator?
what about the delimiter for PATH environment variable? ; for windows, and : for Linux.
Wikipedia helpfully lists the reserved characters for different filesystems. Neither NTFS nor POSIX will accept the null or slash (/) characters in filenames. The slash character is obviously not a good separator, since it's common in POSIX paths, so maybe you could use null.
Of course null isn't suited to all situations (e.g. it isn't usually visible when printed), in which case you might have to use some sort of escaping scheme.
Java, which aims to work across different platforms, doesn't even try to find a common path separator. Instead each platform has its own character, accessible through an API.
Path separator are platform dependent :
For windows, it’s \ and for unix it’s /.
Technically, Unix does allow any character in a folder/filename, except / of course, which would be interpreted as as part of the path.
Windows does only support printable characters and some special characters excluding \ / : * ? " < > |.
In java you can use:
WindowsNTFileSystem
s.split(File.pathSeparator) for windows it will give ; (semicolon)
s.split(File.separator) for windows it will give \ (backward)
Linux
s.split(File.pathSeparator) for windows it will give : (colon)
s.split(File.separator) for windows it will give / (forward)
I would be careful with custom separators because they might break in the future, e.g. if someone uses unicode and your custom separator is part of another character.
I am using a relative file path in one of the cs file to get a location to save an image.
Is there any difference in using ../ and ..// for getting the path.
I don't know if your slashes are actually backslashes, but in c#, you have to escape backslashes.
var path = "..\\file.txt";
path's value is actually ..\file.txt, because the "\" is actually one (escaped) backslash.
However, if it is:
var path = #"..\file.txt";
then it is the same. The # means you want the string as-is, without any escaping, so both "path" variables are the same.
On Unix, and I think MS-DOS and hence Windows follows Unix closely enough here that it is not a difference between the systems, then you can have any number of consecutive slashes at any point in a pathname and it is equivalent to a single slash. Consequently, your two examples are equivalent.
Note that on Windows, a double slash at the start of a path name indicates a UNC path - a machine name followed by a path on that machine.