next up previous contents index
Next: Advanced fill function: Up: List of primitives Previous: Property Lists   Contents   Index

File handling

Primitives Arguments Use
files none By default, lists the contents of the directory. (Equivalent to the ls command for Linux users and the dir command for DOS users)
loadimage, li a: list Load the image file contained in the list. Its upper left corner will be placed at the turtle's location. The only supported formats are .png and .jpg. The path specified must be relative to the current folder. Eg: setdir "C:\\my_images_dir loadimage "turtle.jpg
setdir, setdirectory l: list Specifies the current directory. The path must be absolute. The directory must be specified with a word.
changedirectory, cd m: word Allows to choose the current directory. The path is related to the current directory. You can use the '..' notation to refer to the parent directory.
dir, directory aucun Gives the current directory. The default is the user's home directory, ie /home/your_login for Linux users, C: $ \backslash$WINDOWS for Windows users.
save w: word l:list A good example to explain this: save "test.lgo [proc1 proc2 proc3] saves in the file test.lgo in the current directory the procedues proc1, proc2 et proc3. If the extension .lgo is omitted, it is added by default. The specified word gives a relative path starting from the current directory. This command will not work with an absolute path.
saved w: word saved "test.lgo saves in the file test.lgo in the current directory the collection of procedures currently defined. If the extension .lgo is omitted, it is added by default. The specified word gives a relative path starting from the current directory. This command will not work with an absolute path.
ed, edit li: list or word Open the editor with all the procedure specified in the list li.
edall none Open the editor with all the currently defined procedures.
load w: word Opens and reads the file w. For example, to delete all the defined procedures and load the file test.lgo, you would use: efns load "test.lgo. The specified word gives a relative path starting from the current directory. This command will not work with an absolute path.
openflow id file When you want to read or write in a file, you must first open a flow toward this file. The argument file must be the name of the file you want. You must use a phrase to show the name of the file in the current directory. The id argument is the number given to this flux so as to identify it.
listflow none Shows the list of the various open fluxes with their identifiers.
readlineflow id Opens the flow which identifier corresponds to the number used as argument and then reads a line in this file.
readcharflow id Opens the flux which identifier corresponds to the number used as argument and then reads a character in this file. This primitive sends back a number representing the value of the character (similar to readchar).
writelineflow id list Writes the text line included in the list at the beginning of the file identified thanks to the identifier id. Be careful, the writing is effective only after the flow has been closed by the primitive closeflow.
appendlineflow id list Writes the text line included in the list at the end of the file identified thanks to the identifier id. Be careful, the writing is effective only after the flux has been closed by the primitive closeflow.
closeflow id Closes the flux when its identifier number is written as argument.
endflow? id Sends back "true if it is the end of the file. Otherwise sends back "false.


Here is an example of the use of primitives allowing to read and write in a file. I will give this example in a Windows-type framework. Other users should be able to adapt the following example.

The aim of this file is to create the file c:\example containing the following three lines:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Abcdefghijklmnopqrstuvwxyz
0123456789

# You open a flow towards the desired file. This flow is given the number 2
setdirectory "c:\\
openflow 2 "example
# You type the desired lines
writelineflow 2 [abcdefghijklmnopqrstuvwxyz]
writelineflow 2 [abcdefghijklmnopqrstuvwxyz]
writelineflow 2 [0123456789]
# You close the flux to end the writing
closeflow 2
Now, you can see the writing procedure went alright:
# You open a flow towards the file you want to read. This flow is given the number 0
openflow 0 "c:\\example
# You read the one after the other the different lines from the file
pr readlineflow 0
pr readlineflow 0
pr readlineflow 0
# You close the flow
closeflow 0
if you wish to add the line 'Great !':
setdirectory "c:\\
openflow 1 "example]
appendlineflow 1 [Great!]
closeflow 1

next up previous contents index
Next: Advanced fill function: Up: List of primitives Previous: Property Lists   Contents   Index
Loïc 2008-06-08