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 /lib | |
parent | ec67d98286fcc8c550c6c747c937c5a8fceac749 (diff) | |
download | Nim-5055d307535e5e05e3ec5630107080a9aefbf2ea.tar.gz |
added os.findExe
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/pure/os.nim | 13 |
1 files changed, 13 insertions, 0 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.} |