This is a memo. File :: Stat is a class of objects that stores file information. It is also used to display the user group that owns the file.
class File :: Stat \ (Ruby 2 \ .7 \ .0 Reference Manual )
module Etc \ (Ruby 2 \ .7 \ .0 Reference Manual )
require "etc"
stat = File::Stat.new("aaa.rb")
puts stat.uid #=> 501
puts stat.gid #=> 20
puts stat.size #=> 1738
puts stat.mtime #=> 2020-07-23 16:46:50.584154183 +0900
puts stat.uid #=> 501
puts Etc.getpwuid(stat.uid).name #=> uetennis
puts Etc.getgrgid(stat.gid).name #=> staff
puts File.basename("aaa.rb") #=> aaa.rb
Recommended Posts