krunal shah krunal shah - 1 month ago 10
Ruby Question

Delete all the content from file

I want to remove the content form the list of files.

EDIT :

I have list of files.

file1
file2
file3

Those file containing bunch of lines ...

I want to remove all the lines from each files.

Answer

Looks like you need to truncate file. Do something like:

File.open('/tmp/file', 'w') {|file| file.truncate(0) }