Truncate a file: Difference between revisions

Content added Content deleted
(Adds Clojure solution)
Line 442: Line 442:
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}}==
ELENA 3.4:
<lang elena>import system'io.
<lang elena>import system'io.
import extensions.
import extensions.
file_info extension fileOp
extension<File> fileOp
{
{
set length:length
set length:len
[
[
stream stream := FileStream openForEdit:self.
auto stream := FileStream openForEdit:self.
stream set length:length.
stream length := len.
stream close.
stream close.
Line 457: Line 458:
}
}
program =
public program
[
[
if ('program'arguments length != 3)
if (program_arguments length != 3)
[ console printLine:"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 ].
file_info file := File new('program'arguments[1]).
auto file := File new(program_arguments[1]).
var length := 'program'arguments[2] toInt.
var length := program_arguments[2] toInt.
ifnot (file isAvailable)
ifnot (file isAvailable)
[ console printLine("File ",file," does not exist"). AbortException new; raise ].
[ console printLine("File ",file," does not exist"). AbortException new; raise ].
file set length:length.
file length := length.
].</lang>
]</lang>


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