Unfortunately different operating systems have different rules about the format of file paths.
For example, on Unix and Mac OS, path separator character is /
and on Windows it’s \\
.
For portable programs, it’s important to use functions in filepath
package that understand conventions used by a given operating system.
Note: filepath
package manages OS file paths. There’s also path
package with similar functionality but it always uses /
as path separator.
https://codeeval.dev/gist/8b3a18a7f31bd9e9cd445b7e6809330d
You can join more than 2 path elements.
On Windows the above would return dir\\file.txt
, on Unix and Mac OS it would return dir/file.txt
.
https://codeeval.dev/gist/fc45a61f2426ae0854583877da46bfa1
https://codeeval.dev/gist/3d958c594a3e761d90a11aac2230da17
https://codeeval.dev/gist/1269f937baebc4494f9d833094432bf9
https://codeeval.dev/gist/b700d71acaa1757ed3af88eeb5006e73