Truncate a file: Difference between revisions

Content added Content deleted
Line 411: Line 411:
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.
<lang elena>#import system'io.
#import system'io.
#import extensions.
#import extensions.

#class(extension:file_path)fileOp
extension(file_path) fileOp
{
{
#method set &length:length
set &length:length
[
[
#var(type:stream)stream := FileStream openForEdit &path:self.
stream stream := FileStream openForEdit &path:self.
stream set &length:length.
stream set &length:length.
stream close.
stream close.
]
]
}
}

#symbol program =
program =
[
[
('program'arguments length != 3)?
if ('program'arguments length != 3)
[ console << "Please provide the path to the file and a new length". #throw AbortException new. ].
[ console << "Please provide the path to the file and a new length". AbortException new raise. ].

#var fileName := 'program'arguments@1.
var fileName := 'program'arguments@1.
#var length := ('program'arguments@2) toInt.
var length := ('program'arguments@2) toInt.
(fileName file_path is &available)
ifnot (fileName file_path is &available)
! [ console writeLine:"File ":fileName:" does not exist". #throw AbortException new. ].
[ console writeLine:"File ":fileName:" does not exist". AbortException new raise. ].
fileName file_path set &length:length.
fileName file_path set &length:length.
].</lang>
].</lang>