Created
February 9, 2014 22:15
-
-
Save tuttlem/8906834 to your computer and use it in GitHub Desktop.
INotify example
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
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