LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby】ファイルのタイムスタンプを参照したい時

Posted at

概要 

内容が更新されていた場合のみファイルを処理したいなど、
タイムスタンプ情報を元にしてファイルを処理したい場合などがあります。
その場合は、
File.mtimeメソッド,File.atimeメソッド,File.ctimeメソッド
を使って取得することができます。

使用例

定義 動作
File.mtime 最終更新時刻を返す。
File.atime 最終アクセス時刻を返す。
File.ctime 状態が最後に変更された時刻を返す。状態の変更とは chmod などによるもの

File.mtime

File.mtime(__FILE__) # => 2017-12-03 03:16:22 +0900

File.atime

File.atime(__FILE__) # => 2017-11-28 22:38:44 +0900

File.ctime

IO.write("testfile", "test")
File.ctime("testfile") # => 2017-11-30 22:40:49 +0900
File.chmod(0755, "testfile")
File.ctime("testfile") # => 2017-11-30 22:42:12 +0900

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0