To find the last accessed date of a CSV file in Ruby, you can use the File::Stat
class which represents the status information of a file. The atime
method of File::Stat
returns the last accessed time of the file.
Here's an example code to get the last accessed date of a CSV file:
main.rb294 chars12 lines
In this example, we first require the standard CSV library of Ruby. Then, we define the file path of our CSV file. We use the File.stat
method to get the status information of the file and then call the atime
method to get the last accessed time. Finally, we format the time into a human-readable string using strftime
method and print it to the console.
Note that the atime
method returns the time with the system's timezone, so the output may differ on different systems.
gistlibby LogSnag