path.sep
提供平台特定的路径片段分隔符:
- Windows 上是
\
。 - POSIX 上是
/
。
例如,在 POSIX 上:
'foo/bar/baz'.split(path.sep);
// 返回: ['foo', 'bar', 'baz']
在 Windows 上:
'foo\\bar\\baz'.split(path.sep);
// 返回: ['foo', 'bar', 'baz']
在 Windows 上,正斜杠(/
)和反斜杠(\
)都被接受为路径片段分隔符。
但是, path
方法只添加反斜杠(\
)。
Provides the platform-specific path segment separator:
\
on Windows/
on POSIX
For example, on POSIX:
'foo/bar/baz'.split(path.sep);
// Returns: ['foo', 'bar', 'baz']
On Windows:
'foo\\bar\\baz'.split(path.sep);
// Returns: ['foo', 'bar', 'baz']
On Windows, both the forward slash (/
) and backward slash (\
) are accepted
as path segment separators; however, the path
methods only add backward
slashes (\
).