find the last accessed date of a file in ruby

You can find the last accessed date of a file in ruby by using the File::Stat class. Here's an example:

main.rb
filename = 'path/to/your/file.txt'
filestat = File.stat(filename)
last_access_time = filestat.atime
puts "Last accessed time: #{last_access_time}"
147 chars
5 lines

The File.stat method returns a File::Stat object which contains information about the file. The atime method of this object returns the last access time of the file. You can use the strftime method to format the date and time as needed.

gistlibby LogSnag