tags:

views:

45

answers:

1

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.

+4  A: 

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

File.open('/tmp/file', 'w') {|file| file.truncate(0) }
taro
`File.open('/tmp/file', 'w') {}` should be enough.
Mladen Jablanović
`truncate` is also available as a class method, there is no need to explicitly open the file: `File.truncate('/path/to/file', 0)`. Note, however, that this is documented as "Not available on all platforms." (Which usually means POSIX only, i.e. no JRuby, no IronRuby, no Windows.)
Jörg W Mittag