|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
The Unix `which` commandYou need something like the import std/os import std/strutils proc which(fname: string): string = let sep = if defined(windows): ";" else: ":" dirs = getEnv("PATH").split(sep) for dir in dirs: let path = joinPath(dir, fname) if fileExists(path): return path # return "" # not found proc main() = echo which("date") # /usr/bin/date echo which("nim") # /home/jabba/.nimble/bin/nim echo which("doesnt_exist") # "" (empty string) ########## when isMainModule: main() If the binary is found, the function returns its full path. If not found, then an empty string is returned. |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |