Skip to content

Instantly share code, notes, and snippets.

@rojepp
Created October 19, 2010 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojepp/634908 to your computer and use it in GitHub Desktop.
Save rojepp/634908 to your computer and use it in GitHub Desktop.
Love the elegance of F#. This code looks for the TFS Command line tool and returns Some(path) or None
let findtfpath =
let VS_REGPATHS = [
@"Software\Wow6432Node\Microsoft\VisualStudio\10.0";
@"Software\Microsoft\VisualStudio\10.0";
@"Software\Wow6432Node\Microsoft\VisualStudio\9.0";
@"Software\Microsoft\VisualStudio\9.0";
@"Software\Wow6432Node\Microsoft\VisualStudio\8.0";
@"Software\Microsoft\VisualStudio\8.0"
]
let INSTALLDIR = "InstallDir";
let TF_EXE = "TF.exe";
let check value = match box value with
| null -> None
| _ -> Some(value)
VS_REGPATHS
|> Seq.choose (fun p -> check(Registry.LocalMachine.OpenSubKey(p)))
|> Seq.choose (fun k -> check(k.GetValue(INSTALLDIR, null) :?> string))
|> Seq.map (fun p -> System.IO.Path.Combine(p, TF_EXE))
|> Seq.filter System.IO.File.Exists
|> Seq.tryFind(fun f -> true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment