* add os.absolutePath * fixup * fixup * Fixes absolutePath error message.
This commit is contained in:
parent
f805018461
commit
25bf0d1683
1 changed files with 20 additions and 0 deletions
|
|
@ -296,6 +296,26 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
|
|||
else:
|
||||
if chdir(newDir) != 0'i32: raiseOSError(osLastError())
|
||||
|
||||
proc absolutePath*(path: string, root = getCurrentDir()): string =
|
||||
## Returns the absolute path of `path`, rooted at `root` (which must be absolute)
|
||||
## if `path` is absolute, return it, ignoring `root`
|
||||
runnableExamples:
|
||||
doAssert absolutePath("a") == getCurrentDir() / "a"
|
||||
if isAbsolute(path): path
|
||||
else:
|
||||
if not root.isAbsolute:
|
||||
raise newException(ValueError, "The specified root is not absolute: " & root)
|
||||
joinPath(root, path)
|
||||
|
||||
when isMainModule:
|
||||
doAssertRaises(ValueError): discard absolutePath("a", "b")
|
||||
doAssert absolutePath("a") == getCurrentDir() / "a"
|
||||
doAssert absolutePath("a", "/b") == "/b" / "a"
|
||||
when defined(Posix):
|
||||
doAssert absolutePath("a", "/b/") == "/b" / "a"
|
||||
doAssert absolutePath("a", "/b/c") == "/b/c" / "a"
|
||||
doAssert absolutePath("/a", "b/") == "/a"
|
||||
|
||||
proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||
tags: [ReadDirEffect].} =
|
||||
## Returns the full (`absolute`:idx:) path of an existing file `filename`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue