Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created December 20, 2010 15:16
Show Gist options
  • Select an option

  • Save thinkerbot/748489 to your computer and use it in GitHub Desktop.

Select an option

Save thinkerbot/748489 to your computer and use it in GitHub Desktop.
Illustrate mtime behavior
require 'fileutils'
dir = File.expand_path('../mtime', __FILE__)
file = "#{dir}/file.txt"
format = "%5s:%-20s %s"
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
puts format % [:dir, "mkdir", File.mtime(dir)]
sleep(1)
FileUtils.touch(file)
puts format % [:dir, "touch file", File.mtime(dir)]
sleep(1)
File.open(file, 'w') {|io| io << 'content' }
puts format % [:dir, "mod file", File.mtime(dir)]
sleep(1)
FileUtils.rm(file)
puts format % [:dir, "rm file", File.mtime(dir)]
sleep(1)
FileUtils.touch(file)
puts format % [:file, "touch", File.mtime(file)]
sleep(1)
File.open(file, 'w') {|io| io << 'content' }
puts format % [:file, "mod", File.mtime(file)]
sleep(1)
FileUtils.touch(file)
puts format % [:file, "touch", File.mtime(file)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment