Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #199 Truncate a file at the current file position

Truncate a file F at the given file position.

F.truncate(F.tell())
using System.IO;
var F = new FileStream("F", FileMode.Open)
// advance into F here
F.SetLength(F.Position);
import "os"
err := os.Truncate(F, position)
Truncate(F);
use Path::Tiny qw(path);
my $F = path('F')->openrw;
# ... read some from $F to advance
# position of file handle (not shown) ...
truncate $F, tell $F;
F.truncate(F.pos)

New implementation...
Bart