Introduction
This example shows how to use the builtin Iguana file APIs to load, save and rename files. In this example we just use the bare API calls, but these are all potential candidates for creating small extension/helper functions.
If you have any questions please contact us at support@interfaceware.com.
Using the Code [top]
- Import the Load and Save a File channel from the Builtin: Iguana Files repository
- Experiment with the code to find out how it works
- Adapt the code to your own requirements
This is the github code for the main module:
How it works [top]
- We use iguana.workingDir() to find the working directory
- Save a file, or create it if it doesn’t exist:
- Use
io.open()
to open a file, or create it if it doesn’t exist - Use
io.filehandle.write()
to write data to the file - Use
io.filehandle.close()
to close the file
Note: Closing a file after you have finished using it is good practice particularly with Windows
- Use
- Open a file for reading:
- Use
io.open()
to open a file - Use
io.filehandle.read()
to read data from the file - Use
io.filehandle.close()
to close the file
- Use
- Rename a file
- Use
os.rename()
to rename a file
- Use
- Delete a file
- Use
os.remove()
to delete a file
- Use
More information [top]
- Source code for the main module on github
- API documentation for io, os, and iguana