Created
July 3, 2012 19:48
-
-
Save brianium/3042459 to your computer and use it in GitHub Desktop.
watcher F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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