diff options
author | Araq <rumpf_a@web.de> | 2010-10-31 02:12:18 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2010-10-31 02:12:18 +0200 |
commit | 5055d307535e5e05e3ec5630107080a9aefbf2ea (patch) | |
tree | 926e9a83986c54fa7ceb2ba0923ab9439bd75a1c | |
parent | ec67d98286fcc8c550c6c747c937c5a8fceac749 (diff) | |
download | Nim-5055d307535e5e05e3ec5630107080a9aefbf2ea.tar.gz |
added os.findExe
-rwxr-xr-x | lib/pure/os.nim | 13 | ||||
-rwxr-xr-x | tools/nimrepl.nim | 12 | ||||
-rwxr-xr-x | web/news.txt | 1 |
3 files changed, 14 insertions, 12 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index a1dd5450d..229fad441 100755 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1231,4 +1231,17 @@ proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1".} = close(f) else: OSError() +proc findExe*(exe: string): string = + ## Searches for `exe` in the current working directory and then + ## in directories listed in the ``PATH`` environment variable. + ## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe` + ## is added an ``.exe`` file extension if it has no extension. + result = addFileExt(exe, os.exeExt) + if ExistsFile(result): return + var path = os.getEnv("PATH") + for candidate in split(path, pathSep): + var x = candidate / result + if ExistsFile(x): return x + result = "" + {.pop.} diff --git a/tools/nimrepl.nim b/tools/nimrepl.nim index 989689add..432ca1356 100755 --- a/tools/nimrepl.nim +++ b/tools/nimrepl.nim @@ -14,18 +14,6 @@ when defined(tinyc): else: const runCmd = "c -r" -when not defined(findExe): - # candidate for the stdlib: - proc findExe(exe: string): string = - ## returns exe if the exe cannot be found - result = addFileExt(exe, os.exeExt) - if ExistsFile(result): return - var path = os.getEnv("PATH") - for candidate in split(path, pathSep): - var x = candidate / result - if ExistsFile(x): return x - result = "" - var nimExe = findExe("nimrod") if nimExe.len == 0: nimExe = "../bin" / addFileExt("nimrod", os.exeExt) diff --git a/web/news.txt b/web/news.txt index 9569a9cc3..af0ce1fbd 100755 --- a/web/news.txt +++ b/web/news.txt @@ -17,6 +17,7 @@ Additions --------- - Added ``re.findAll``, ``pegs.findAll``. +- Added ``os.findExe``. 2010-10-20 Version 0.8.10 released |