Directory not found. Works on simulator but not iOS

I have a very simple Lua program. I developed this program on an Apple Mac using Corona. When I ran the program in the Corona simulator, it worked as expected. When I deployed to my iPad Retina, it did not work. I used Xcode on my mac to see the log.

Does anyone know why the program does not work?

project has a directory called sub1, which contains a dir and file.

The program (main.lua):

print (“START”)

 

local lfs = require(“lfs”)

local cdir = lfs.currentdir()

print (“CDIR:”…cdir)

 

local sub1 = cdir … “/” … “sub1”

print (“SUB1:” … sub1)

 

for file in lfs.dir(sub1) do

    print (“SUB1FILE:”…file)

end

 

print (“END”)

os.exit(0)

Output on the simulator is like this;

START

CDIR:/Users/martin/NetBeansProjects/readDirTest

SUB1:/Users/martin/NetBeansProjects/readDirTest/sub1

SUB1FILE:.

SUB1FILE:…

SUB1FILE:sub1.txt

SUB1FILE:sub2

END

0

But when I deployed it on my iPad, the log shows this error;

50.6.10 / 2014.2393

Oct 29 14:41:28 Martins-iPad readDirTest[325] <Warning>: START

Oct 29 14:41:28 Martins-iPad readDirTest[325] <Warning>: CDIR:/

Oct 29 14:41:28 Martins-iPad readDirTest[325] <Warning>: SUB1://sub1

Oct 29 14:41:28 Martins-iPad readDirTest[325] <Warning>: Runtime error

/Users/martin/NetBeansProjects/readDirTest/main.lua:12: cannot open //sub1: No such file or directory

stack traceback:

[C]: in function ‘dir’

/Users/martin/NetBeansProjects/readDirTest/main.lua:12: in main chunk

Oct 29 14:41:28 Martins-iPad locationd[54] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

 

I do not know how to move forward.

Has the sub1 dir not been included with the project?

Is the lfs.currentdir() returning an incorrect path? (it seems to be returning ‘/’)

Amazingly this works on my iPad (but DOES NOT WORK in the simulator - which seems totally WRONG to me, it should work or not work on both) … and i have no idea WHAT would work on an android… might be in the situation where i have to write 3 sets of code, for iOS, Android and Corona Simulator… LOL.

print (“START”)

 

local lfs = require(“lfs”)

local cdir = system.pathForFile("", system.ResourcesDirectory)

print (“CDIR:”…cdir)

 

local sub1 = cdir … “/sub1”

print (“SUB1:” … sub1)

 

for file in lfs.dir(sub1) do

    print (“SUB1FILE:”…file)

end

 

print (“END”) 

this works for both;

local function getDir(dir)

    – dir = “/sub”

    

    – 1. simulator

    local lfs = require(“lfs”)

    local basedir = lfs.currentdir();

    local new = basedir  … dir

    local st,msg = lfs.attributes(new)

    if ( st ) then

        print ( “Found (”…new…") size ("… st.size …") bytes")

        return new

    end

    – 2. iOS

    basedir = system.pathForFile("", system.ResourcesDirectory)

    new = basedir … dir

    st,msg = lfs.attributes(new)

    if ( st ) then

        print ( “Found (”…new…") size ("… st.size …") bytes")

        return new

    end

    print ("FAIL CITY: "…msg)

    return nil

end

MASSIVE WARNING to anyone reading this. it is impossible to read directories on Android because the app is all bundled as an apk/zip file and Corona/Lua cannot read it.

Amazingly this works on my iPad (but DOES NOT WORK in the simulator - which seems totally WRONG to me, it should work or not work on both) … and i have no idea WHAT would work on an android… might be in the situation where i have to write 3 sets of code, for iOS, Android and Corona Simulator… LOL.

print (“START”)

 

local lfs = require(“lfs”)

local cdir = system.pathForFile("", system.ResourcesDirectory)

print (“CDIR:”…cdir)

 

local sub1 = cdir … “/sub1”

print (“SUB1:” … sub1)

 

for file in lfs.dir(sub1) do

    print (“SUB1FILE:”…file)

end

 

print (“END”) 

this works for both;

local function getDir(dir)

    – dir = “/sub”

    

    – 1. simulator

    local lfs = require(“lfs”)

    local basedir = lfs.currentdir();

    local new = basedir  … dir

    local st,msg = lfs.attributes(new)

    if ( st ) then

        print ( “Found (”…new…") size ("… st.size …") bytes")

        return new

    end

    – 2. iOS

    basedir = system.pathForFile("", system.ResourcesDirectory)

    new = basedir … dir

    st,msg = lfs.attributes(new)

    if ( st ) then

        print ( “Found (”…new…") size ("… st.size …") bytes")

        return new

    end

    print ("FAIL CITY: "…msg)

    return nil

end

MASSIVE WARNING to anyone reading this. it is impossible to read directories on Android because the app is all bundled as an apk/zip file and Corona/Lua cannot read it.