Skip to content

Instantly share code, notes, and snippets.

@brianium
Created July 3, 2012 19:48
Show Gist options
  • Save brianium/3042459 to your computer and use it in GitHub Desktop.
Save brianium/3042459 to your computer and use it in GitHub Desktop.
watcher F#
open System;
open System.IO;
open Microsoft.FSharp.Collections;
//setup the watcher and events
let watcher = new FileSystemWatcher(@"C:\Users\brians\Python")
let logFileInfo (args:FileSystemEventArgs) = Console.WriteLine(args.Name)
let events = [watcher.Changed; watcher.Created; watcher.Deleted] |> List.iter(fun e -> e.Add(logFileInfo))
//read from console
let readlines = Seq.initInfinite (fun _ -> Console.ReadLine())
let readline line = if line = "q" then Some(line) else None
//run that stuff
watcher.EnableRaisingEvents <- true;
Console.WriteLine(@"Press 'q' to quit listening")
Seq.pick readline readlines |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment