Where should I put files with pathForFile ?

Hi,
I am trying to load a file, it doesn’t find the file, I don’t know what I did wrong?
I added a Documents folder and put the filename.txt inside (and also in the same folder as the lua files), and it says :

File error: /Users/lincoln/Library/Application Support/Corona Simulator/testua-5AB745870794E893FF8732F713128C7D/Documents/map1.txt: No such file or directory

I am on Mac, so I also tried .rtf file, but same error.

If I use system.ResourceDirectory instead of DocumentsDirectory, it triggers an error at “io.open” : “Bad argument #1 to ‘open’ (string expected, got nil)”

local function loadS()
    local path = system.pathForFile( "map1.txt", system.DocumentsDirectory )
    local file, errorString = io.open( path, "r" )
  
    if not file then
      print( "File error: " .. errorString )
    else
      local contents = file:read( "*a" )
      tt = tonumber( contents )
      print("after read file : "..tt)
      io.close( file )
  end
  file = nil
end

What do you mean by:

This is something that you don’t add manually, it should be there for you!

If you have created a folder inside the project folder next to main.lua, then is not right

system.DocumentsDirectory is a system directory created for you in run time
if you wish to use the project folder then use:

local path = system.pathForFile( "map1.txt" )

1 Like

thank you, ok it works :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.