RosettaCodeData/Task/Truncate-a-file/Mathematica/truncate-a-file.math
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

5 lines
240 B
Text

Truncate[file_, n_] := Module[{filename = file, nbbytes = n, temp},
temp = $TemporaryPrefix <> filename;
BinaryWrite[temp, BinaryReadList[filename, "Byte", nbbytes]];
Close[temp]; DeleteFile[filename]; RenameFile[temp, filename];
]