-
-
Save thibaudgg/7659392 to your computer and use it in GitHub Desktop.
Fix dir2 path
This file contains 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
# 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