File IO functionality for Documents and Dropbox

I really would like some actual lua file io functionality within the codea dev environment would be really nice.

What exactly would you like? I fine read/write local, project and global to be great. You can eaisly read and write from dropbox as well.

Here is some code to write to and read from a file. The file is written to the Documents folder. The file seems to show in the Documents folder only after Codea is closed and open again and it needs a .png extension. It doesn’t work if I try to write to the Dropbox folder. Maybe I don’t have the correct path name. Also, I haven’t found a way to do a directory list, so keep track of what files you write.

function setup()
    local file = os.getenv("HOME").."/Documents/myFile.png"
    local testData = "This is test data to be written to a file."

function writeData(file,td)
    print("----- start write -----")
    wFd =,"w")
    print("----- stop write -----\

function readData(file)
    print("----- start read -----")
    rFd =,"r")
    while 1 do
        if data==nil then
    print("----- stop read -----\

@dave1707 that is elegant. The likes if the os.getenv function is not exposed in the codea reference library.

@BriarFox I really am wanting to create files with any extension, write to and read from these files for the likes of 3d modelling and cad purposes using a predefined file specification

Ok dave I have tested the above sample and it works perfectly. I also tested using the file extension .txt this did not show up in the sprite pack as codea has a selective filter over te sprite pack viewer but when I synced my Dropbox it transferred out my txt file.

My next question does anyone have enough knowledge on the iOS Filesytem to allow me to save straight to Dropbox with out syncing. Ie does OS.getenv change to (“Dropbox”)


I have tried your example changing the .png file extension to .txt. I then plugged ipad into my PC & browsed using IExplorer and indeed found that the file had been created, now from what I can see from the codea app structure to send a fil to the Dropbox you need to have the path as …/Documents/Dropbox.spritepack/myFile.png.

Hope this helps you some I know you helped me out

To save directly to dropbox you might want to look into http.request() and dropbox api.


I seen that as there are no folders containing a respoitry for files which are queued for upload simply a folder containing cached files

.@michaelmaguin Thanks for the path to Dropbox. Since I’m just using an iPad, I don’t have access to the file system to see how the paths are made. A lot of stuff I do is just trial and error. I still would like to see a directory command.