Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created February 9, 2014 22:15
Show Gist options
  • Save tuttlem/8906834 to your computer and use it in GitHub Desktop.
Save tuttlem/8906834 to your computer and use it in GitHub Desktop.
INotify example
module Main where
import Control.Concurrent (threadDelay)
import System.INotify
main :: IO ()
main = do
-- the paths that we'll monitor
let paths = [ "/tmp", "/home/user" ]
-- setup INotify
withINotify $ \n -> do
-- monitor each predefined path, and respond using printEvent
mapM_ (\f -> addWatch n [Modify, CloseWrite] f (printEvent f)) paths
-- this gives "addWatch" some time to collect some data
threadDelay 10000000
where
-- print the file and event to the console
printEvent :: FilePath -> Event -> IO ()
printEvent f e = putStrLn (f ++ ": " ++ show e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment