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.

Join a path

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.

Split a path into a directory and file

https://codeeval.dev/gist/fc45a61f2426ae0854583877da46bfa1

Split list of paths

https://codeeval.dev/gist/3d958c594a3e761d90a11aac2230da17

Get file name from path

https://codeeval.dev/gist/1269f937baebc4494f9d833094432bf9

Get directory name from path

https://codeeval.dev/gist/b700d71acaa1757ed3af88eeb5006e73

Get file extension

https://codeeval.dev/gist/e32564c7ba421b1d8ab2c0ab31b6c5c6