Truncate a file: Difference between revisions

Content added Content deleted
(Added Kotlin)
Line 434: Line 434:
Cannot open file "<File name with full path>. The system cannot find the file specified.
Cannot open file "<File name with full path>. The system cannot find the file specified.
=={{header|Elena}}==
=={{header|Elena}}==
<lang elena>#import system'io.
<lang elena>import system'io.
#import extensions.
import extensions.
extension(file_path) fileOp
file_info extension fileOp
{
{
set &length:length
set length:length
[
[
stream stream := FileStream openForEdit &path:self.
stream stream := FileStream openForEdit:self.
stream set &length:length.
stream set length:length.
stream close.
stream close.
Line 452: Line 452:
[
[
if ('program'arguments length != 3)
if ('program'arguments length != 3)
[ console << "Please provide the path to the file and a new length". AbortException new raise. ].
[ console printLine:"Please provide the path to the file and a new length". AbortException new; raise ].
var fileName := 'program'arguments@1.
file_info file := File new('program'arguments[1]).
var length := ('program'arguments@2) toInt.
var length := 'program'arguments[2] toInt.
ifnot (fileName file_path is &available)
ifnot (file isAvailable)
[ console writeLine:"File ":fileName:" does not exist". AbortException new raise. ].
[ console printLine("File ",file," does not exist"). AbortException new; raise ].
fileName file_path set &length:length.
file set length:length.
].</lang>
].</lang>