Path separator for Windows and Unix
Asked Answered
A

6

25

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?

Abseil answered 9/2, 2010 at 9:21 Comment(1)
Just a note that this question seems to be about delimiters not separators.Prado
T
9

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.

Trumaine answered 9/2, 2010 at 9:33 Comment(0)
K
76

what about the delimiter for PATH environment variable? ; for windows, and : for Linux.

Klarrisa answered 9/2, 2010 at 9:37 Comment(2)
You win the prize called - "Being the only one who answered the question asked"Mildamilde
Filenames can contain : on Linux though.Detestable
T
9

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.

Trumaine answered 9/2, 2010 at 9:33 Comment(0)
P
8

Path separator are platform dependent :

For windows, it’s \ and for unix it’s /.

Photometry answered 16/7, 2014 at 6:52 Comment(3)
You're talking about directory separators, not path separators. Path separators are the characters (semicolons on Windows, colons on Unix) that separate individual elements of a value that represents multiple paths.Brushoff
"directory separators" are also widely known as path separators, somewhat confusingly. In this case I'm pretty sure OP was talking about file paths, rather than PATH.Detestable
Also worth pointing out that / works perfectly well on Windows unless an app goes out of its way to stop it working.Detestable
I
3

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 \ / : * ? " < > |.

Irrespective answered 9/2, 2010 at 9:27 Comment(5)
So, for Unix, there is no any way to join several paths in one string?Abseil
@Abseil - Maybe you can use a home-made-separator like: /home/user/tiutalk/_____SEPARATOOOOORRR_____/var/www/_____SEPARATOOOOORRR_____/bin/dump/Glyptic
or string like "#p#p...#p#p", where # is number of characters in the path and p is the pathAbseil
@user269354: Would be a possibility, as TiuTalk suggested, just use a pattern which will not be part of the paths and which you can easily recognize and extract. If you can be sure that there'll never be numbers in those paths, then yes, use that one.Irrespective
@user269354, Unix uses : (colon) to seperate paths, but since Windows has : in root directory names like C://, it uses ; (semicolon) to seperate pathsAngadresma
E
2

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)
Elianaelianora answered 26/8, 2020 at 6:5 Comment(0)
Q
-1

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.

Quodlibet answered 9/2, 2010 at 9:31 Comment(1)
Note that this will primarily be a concern for characters defined outside the base ASCII 127, barring the involvement of an extremely flawed character set implementation.Ger

© 2022 - 2024 — McMap. All rights reserved.