Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

File IO functionality for Documents and Dropbox

edited May 2013 in Suggestions Posts: 19

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


  • BriarfoxBriarfox Mod
    edited May 2013 Posts: 1,542

    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.

  • dave1707dave1707 Mod
    edited May 2013 Posts: 8,810

    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."          writeData(file,testData)         readData(file) end function writeData(file,td)     print("----- start write -----")     wFd =,"w")     wFd:write(td)     wFd:close()     print("----- stop write -----\n") end function readData(file)     print("----- start read -----")     rFd =,"r")     while 1 do         data=rFd:read()         if data==nil then             rFd:close()             break         end         print(data)     end     print("----- stop read -----\n") end
  • @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

  • @dave1707

    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

  • 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")

  • BriarfoxBriarfox Mod
    Posts: 1,542

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

  • @briarfox

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

  • dave1707dave1707 Mod
    Posts: 8,810

    .@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.

Sign In or Register to comment.