Path separator for Windows and Unix

霸气de小男生 提交于 2019-12-12 09:33:53

问题


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?


回答1:


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.




回答2:


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




回答3:


path separator are platform dependent :

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




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/2227925/path-separator-for-windows-and-unix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!