Created
November 22, 2017 11:06
-
-
Save Peranikov/3680bff5573832f436423ce74f5c24ae to your computer and use it in GitHub Desktop.
5–7-2 Fileオブジェクトの操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ファイルのロック | |
File.open 'counter', File::RDWR | File::CREAT do |f| | |
f.flock File::LOCK_EX | |
count = f.read.to_i | |
f.rewind | |
f.write count.succ | |
end | |
# ファイルに関する情報の取得 | |
File.open 'counter' do |f| | |
# 最後にアクセスした日時 | |
p f.atime | |
# 最後に状態を変更した日時 | |
p f.ctime | |
# 最後に更新した日時 | |
p f.mtime | |
# ファイルサイズ | |
p f.size | |
end | |
# ファイルの情報 | |
stat = File.open('counter', &:stat) | |
# ファイルタイプ | |
stat.ftype | |
stat.file? | |
stat.directory? | |
stat.symlink? | |
stat.pipe? | |
stat.socket? | |
# ファイルの状態 | |
stat.writable? | |
stat.readable? | |
stat.executable? | |
# 自身がオーナーか | |
stat.owned? | |
# ファイルオーナーの情報 | |
stat.gid | |
stat.uid | |
# inode番号 | |
stat.ino | |
# デバイス番号 | |
stat.dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment