Skip to content

Instantly share code, notes, and snippets.

@thibaudgg
Forked from riverock/gist:7600741
Last active December 29, 2015 10:49
Show Gist options
  • Save thibaudgg/7659392 to your computer and use it in GitHub Desktop.
Save thibaudgg/7659392 to your computer and use it in GitHub Desktop.
Fix dir2 path
# Using Ruby 2.0.0p195 and listen 2.3.0
require 'listen'
require 'fileutils'
dir1 = '/Users/blue39/tmp/dir1'
FileUtils.remove_dir(dir1, true)
FileUtils.mkdir_p(dir1)
dir2 = '/Users/blue39/tmp/dir2'
FileUtils.remove_dir(dir2, true)
FileUtils.mkdir_p(dir2)
listener1 = Listen.to(dir1) do | modified, added, removed |
puts "listener1: modified: #{modified.inspect}, added: #{added.inspect}, removed: #{removed.inspect}"
end
listener2 = Listen.to(dir2) do | modified, added, removed |
puts "listener2: modified: #{modified.inspect}, added: #{added.inspect}, removed: #{removed.inspect}"
end
listener1.start
listener2.start
# Add a file to dir1
file_path = "#{dir1}/test.txt"
file = File.open(file_path, "w")
file.write("Testing")
file.close
sleep 1 # give listener1 time to respond to this file event
# Add a file to dir2
file_path = "#{dir2}/test.txt"
file = File.open(file_path, "w")
file.write("Testing")
file.close
sleep 1 # give listener2 time to respond to this file event
listener1.stop
listener2.stop
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment