summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/pure/os.nim13
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.}