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?
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.
what about the delimiter for PATH environment variable? ;
for windows, and :
for Linux.
:
on Linux though. –
Detestable 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 /
.
/
works perfectly well on Windows unless an app goes out of its way to stop it working. –
Detestable 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 \ / : * ? " < > |
.
:
(colon) to seperate paths, but since Windows has :
in root directory names like C://
, it uses ;
(semicolon) to seperate paths –
Angadresma 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.
© 2022 - 2024 — McMap. All rights reserved.