Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created October 2, 2016 21:20
Show Gist options
  • Save vbfox/0cfc602eab588e0660af63d854ce73fe to your computer and use it in GitHub Desktop.
Save vbfox/0cfc602eab588e0660af63d854ce73fe to your computer and use it in GitHub Desktop.
F# module for WindowsPath access (Useful in FAKE scripts)
module WindowsPath =
open System
open System.IO
let path = lazy (Environment.GetEnvironmentVariable("PATH").Split(';') |> List.ofArray)
let pathExt = lazy (Environment.GetEnvironmentVariable("PATHEXT").Split(';') |> List.ofArray)
let find names =
path.Value
|> Seq.collect (fun dir -> names |> List.map (fun name -> Path.Combine(dir, name)))
|> Seq.tryFind(File.Exists)
let findProgram name =
pathExt.Value
|> List.map ((+) name)
|> find
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment