Skip to content

Commit

Permalink
add os.absolutePath
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jul 5, 2018
1 parent a1457bf commit 4e4ff34
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
else:
if chdir(newDir) != 0'i32: raiseOSError(osLastError())

proc absolutePath*(path: string, base: string = nil):string=
if isAbsolute(path): return path
let base2 = if base == nil: getCurrentDir() else: base
return joinPath(base2, path)

when isMainModule:
assert absolutePath("a", "b") == "b" / "a"
assert absolutePath("a", "b/") == "b" / "a"
when defined(Posix):
assert absolutePath("/a", "b/") == "/a"

proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
tags: [ReadDirEffect].} =
## Returns the full (`absolute`:idx:) path of the file `filename`,
Expand Down

0 comments on commit 4e4ff34

Please sign in to comment.