Skip to content
Browse files


  • Loading branch information...
lihaoyi committed Jun 3, 2019
1 parent f5b12bc commit 40da7dcc84111292262b413ac3dfa7b510b3e751
Showing with 17 additions and 0 deletions.
  1. +17 −0 post/36 - How to work with Files in
@@ -86,6 +86,23 @@ res3: os.Path = root/'Users/'lihaoyi/'Github/'blog/'post
res4: os.Path = root/'Users/'lihaoyi/'Github/'blog

Note that you can only append single path segments to a path using the `/`
operator on strings, e.g. this is not allowed:

@ os.home / "Github/blog"
os.PathError$InvalidSegment: [Github/blog] is not a valid path segment.
[/] is not a valid character to appear in a path segment. If you want to parse
an absolute or relative path that may have multiple segments, e.g. path-strings
coming from external sources use the Path(...) or RelPath(...) constructor calls
to convert them.

As the error message suggests, you need to use the [os.RelPath](#relative-paths)
constructor in order to construct a relative path of more than one segment. This
helps avoid confusion between working with individual path segments (as
`String`s) and working with more general relative paths (as `os.RelPath`s)

You can also use the special `os.up` path segment to move up one level:


0 comments on commit 40da7dc

Please sign in to comment.
You can’t perform that action at this time.