Created
June 27, 2016 06:45
-
-
Save sks147/72d13153b79cff874376de32845b78f7 to your computer and use it in GitHub Desktop.
Getting metadata of a file using ruby
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
# pass file arguments in double quotes | |
# e.g last_modified("/etc/passwd") | |
def last_modified(file) | |
t1 = File.stat(file).ctime | |
t2 = Time.now | |
elapsed = (t2-t1)/(60*60*24) | |
puts "#{file} was modified #{elapsed} days ago." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment