Ruby/File Directory/truncate
Материал из Wiki.crossplatform.ru
Erase all existing content
f = "log.messages" # Filename File.truncate(f, 0) # Erase all existing content
File.truncate
filename = "truncate.txt" f = open(filename, "w") do |f| f << "this is a test." end File.size(filename) File.truncate(filename, 30) File.size(filename) open(filename) { |f| f.read }