Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | File | ctime

概要

File.ctime

詳細

指定ファイルの最終変更時刻を返却する
chmod等による変更の時間。

サンプル

コード
# encoding: utf-8

def create_file(filename, contents)
  File.open(filename, 'a:utf-8') do |f|
    f.print contents
  end
end

filename = 'sample.txt'
File.open(filename, "w") {|f|f.print ''}
puts File.ctime(filename)
sleep 1
change_count = File.chown(-1, -1, filename)
puts File.ctime(filename)
出力
2014-01-06 22:28:02 +0900
2014-01-06 22:28:03 +0900