File and Device I/O
To do input or output on a file or device you must first open the file or device, then use the routines
below to read or write to it, then close the file or device.
open() returns a file number to use as the first argument of the other I/O routines.
Certain files/devices are opened for you automatically (as text files):
- 0 - standard input
- 1 - standard output
- 2 - standard error
open | - | open a file or device |
close | - | close a file or device |
flush | - | flush out buffered data to a file or device |
puts | - | output a string to a file or device |
printf | - | formatted print to a file or device |
sprintf | - | formatted print returned as a string |
- | print a Phix object with {,,} to show the structure | |
sprint | - | return a printed Phix object as a string |
? x | - | shorthand for print(1, x) |
getc | - | read the next character from a file or device |
gets | - | read the next line from a file or device |
get_text | - | read a whole text file as a single string or sequence of lines |
seek | - | move to any byte position within an open file |
where | - | report the current byte position in an open file |
lock_file | - | lock a file or device |
unlock_file | - | unlock a file or device |
get_key | - | check for key pressed by the user, do not wait |
wait_key | - | wait for user to press a key |
dir | - | return complete info on all files in a directory |
walk_dir | - | recursively walk through all files in a directory |
current_dir | - | return the name of the current directory |
chdir | - | change to a new current directory |