added os.findExe

This commit is contained in:
Araq
2010-10-31 02:12:18 +02:00
parent ec67d98286
commit 5055d30753
3 changed files with 14 additions and 12 deletions

View File

@@ -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.}