Guest User

file_watcher

a guest
Mar 12th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. puts "what file should I watch?"
  2. watch = gets
  3. puts "ok, if anything changes in that file I'll put it in changelog.txt"
  4. oldlog = nil
  5. newlog = nil
  6.  
  7. ##loop forever
  8. loop do
  9.  
  10. ##if the file has changed
  11. if oldlog != (newlog = File.read(watch))
  12. ## write in the change log
  13. File::open('changelog.txt','w') do |f|
  14. f << Diffy::Diff.new(oldlog,newlog)
  15. end
  16. end
  17.  
  18. ##make a copy of the file for next time around
  19. oldlog = newlog
  20.  
  21. ##sleep for a moment
  22. sleep(1)
  23. end
Add Comment
Please, Sign In to add comment