mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-26 12:55:06 +00:00
added os.findExe
This commit is contained in:
@@ -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.}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ Additions
|
||||
---------
|
||||
|
||||
- Added ``re.findAll``, ``pegs.findAll``.
|
||||
- Added ``os.findExe``.
|
||||
|
||||
|
||||
2010-10-20 Version 0.8.10 released
|
||||
|
||||
Reference in New Issue
Block a user