mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 20:17:42 +00:00
* add os.absolutePath * fixup * fixup * Fixes absolutePath error message.
This commit is contained in:
committed by
Dominik Picheta
parent
f805018461
commit
25bf0d1683
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user