File.open('data/counter', File::RDWR | File::CREAT) do |f|
f.flock File::LOCK_EX
count = f.read.to_i
f.rewind
f.write count.succ
end
1
`type counter`
"5"
File.open 'data/counter' do |f|
p(f.atime)
p(f.ctime)
p(f.mtime)
f.size
end
2017-11-22 19:43:22 +0900 2017-11-22 19:43:22 +0900 2017-11-22 19:45:38 +0900
1
stat = File.open('data/counter', &:stat)
puts "### file ###"
p(stat.ftype)
p(stat.file?)
p(stat.directory?)
p(stat.symlink?)
p(stat.pipe?)
p(stat.socket?)
puts "### File status ###"
p(stat.writable?)
p(stat.readable?)
p(stat.executable?)
puts "### Owner ###"
p(stat.owned?)
p(stat.gid)
p(stat.uid)
puts "### inode ###"
p(stat.ino)
puts "### Device number ###"
p(stat.dev)
### file ### "file" true false false false false ### File status ### true true false ### Owner ### true 0 0 ### inode ### 15481123719132246 ### Device number ### 0
0
次回は 5-7-3 ファイルの操作