iOS / Mac Path problem

Hi everybody,

I’m almost finishing my app and I’m having some troublesm with iOS/Mac.

While I’m at Windows/Android its runs perfectly, no problem occurs. But when I open the simulator at Mac or Iphone it seems that it can’t read the file or locate it.

Here’s the function that checks if the file exists:

function file\_exists(name) local f=io.open(dataPath..name,"r")  if f~=nil then     io.close(f)     --print("file exists")     return true     else         return false     end end

This function always returning false only if I’m at Mac/Iphone.

The dataPath variable it’s defined at this function:
 

    for line in Config:lines() do         print(line)         print(string.find(line,"false"))         if (string.find(line,"false") ~= nil) then             print("-false")             dataPath = system.pathForFile("",system.TemporaryDirectory)             save = false             downloadWait("http://alagarta.com/app/info.txt","appinfo.txt","rewrite")             --print("temp: ",system.pathForFile("",system.TemporaryDirectory))         else             print("-true")             dataPath = system.pathForFile("",system.DocumentsDirectory)             save = true             downloadWait("http://alagarta.com/app/info.txt","appinfo.txt","rewrite")             --print("doc:", system.pathForFile("",system.DocumentsDirectory))         end     end

The strange thing is: I check manually if the file exists and it’s there. The same function works fine at my android and Windows, so I think it could be something related to dataPath or permission to read files, but I couldn’t find topic about that.

PS: checking the 2nd code (the one where its defined the dataPath), I really don’t think that the problem is with reading files, because it could read the config.txt

Thank You,

Pedro.

Hi Pedro,

May I ask why you’re pointing to an “empty” file name by using “” as the first argument, as here? Are you simply trying to get the path to that directory, but not a specific file within it?

[lua]

system.pathForFile("",system.DocumentsDirectory)

[/lua]

Best regards,

Brent

Hi Brent,

Well this was the only way that it worked to check if the file exists after it’s downloaded. When I tried to check using the name and system.pathForFile, it always returned that the file couldn’t have been found. As you can see :
nKG7HMU.png

I diagnosed the problem, what is happening is that : At windows/android system.pathForFile("",system.DocumentsDirectory) returns me the path with “” at the end, while at Mac/iOS it don’t. So I manually treat that with some code lines, but I don’t think that is the best way, but it is the way it worked.

Hi Pedro,

May I ask why you’re pointing to an “empty” file name by using “” as the first argument, as here? Are you simply trying to get the path to that directory, but not a specific file within it?

[lua]

system.pathForFile("",system.DocumentsDirectory)

[/lua]

Best regards,

Brent

Hi Brent,

Well this was the only way that it worked to check if the file exists after it’s downloaded. When I tried to check using the name and system.pathForFile, it always returned that the file couldn’t have been found. As you can see :
nKG7HMU.png

I diagnosed the problem, what is happening is that : At windows/android system.pathForFile("",system.DocumentsDirectory) returns me the path with “” at the end, while at Mac/iOS it don’t. So I manually treat that with some code lines, but I don’t think that is the best way, but it is the way it worked.