Truncate a file: Difference between revisions

Content added Content deleted
Line 347: Line 347:
If you try to truncate a non-existent file using a stream you will get an EFOpenError exception with the message:
If you try to truncate a non-existent file using a stream you will get an EFOpenError exception with the message:
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}}==
<lang elena>#import system.
#import system'io.
#import extensions.

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

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

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


=={{header|Erlang}}==
=={{header|Erlang}}==