Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Latest commit

 

History

History
29 lines (21 loc) · 594 Bytes

ftruncate.markdown

File metadata and controls

29 lines (21 loc) · 594 Bytes

We use the ftruncate function in PHP to truncate a file to a given length.

{{code:php $f = fopen('/path/to/foobar', 'w') ftruncate($f, 10); fclose($f); }}

The same task can be accomplished in Ruby with the File#truncate method:

{{code:ruby File.open('/path/to/foobar', 'w') do |f| f.truncate(10) end }}

Ruby also provides the File.truncate class method for convenience. It allows you to truncate a file without opening it yourself.

{{code:ruby File.truncate('/path/to/foobar', 10) }}

{{related: filesystem/fopen
filesystem/fseek }}