this documentation is work-in-progress, edit here (md).
File
The File object provides basic access to the file system. You can use this object to read entire files into a variable at once, or write variables to files at once. Line by line reading is also supported. These are the most common file I/O operations in a scripting language. Advanced file operations require the use of FFI through the server plugin or a separate IO plugin.
[ File ] path
Example:
#Linux
>> f := File new: (Path tmp: ['test.txt']).
Out write: f path, stop.
Result:
[ File ] string
Example:
#Linux
>> x := File new.
Out write: x, stop.
>> y := File new: (Path /tmp: ['a.txt']).
Out write: y, stop.
Result:
[ File ] read
Example:
>> f := File new: (Path /tmp: ['test.txt']).
f write: ['test'].
>> q := File new: (Path /tmp: ['test.txt']).
Out write: q read, stop.
Result:
[ File ] write: [ String ]
Example:
>> f := File new: (Path /tmp: ['test.txt']).
f write: ['test'].
>> q := File new: (Path /tmp: ['test.txt']).
Out write: q read, stop.
Result:
[ File ] append: [ String ]
Example:
>> x := File new: (Path /tmp: ['a.txt']).
x write: ['123'].
Out write: x read, stop.
x append: ['345'].
Out write: x read, stop.
Result:
[ File ] exists
Example:
>> x := File new: (Path /tmp unknown).
Out write: x exists, stop.
Result:
[ File ] delete
Example:
>> x := File new: (Path /tmp: ['a.txt']).
x write: ['abc'].
Out write: x exists, stop.
x delete.
Out write: x exists, stop.
Result:
[ File ] size
Example:
>> x := File new: (Path /tmp: ['a.txt']).
x write: ['abc'].
Out write: x size, stop.
x append: ['def'].
Out write: x size, stop.
Result:
[ File ] list: [ String ]
Example:
#Linux
>> x := File list: Path /usr games.
Out write: x, stop.
Result:
[ File ] lines: [ Code ]
Example:
>> f := File new: ['/tmp/lines.txt'].
f write: ['abc\n123\ndefg\naa'].
# now read line by line
f lines: { :line
Out write: line, stop.
}.
Result: