Hi, I’ve got a question.
I’ve got this code that reads all the files in a folder (at the root of the project) and does some stuff with them:
local levelsFile, errorString = io.open(system.pathForFile("migrations/levels/levels-001.json"), "r") io.close(levelsFile) levelsFile = nil -- Read all files in the folder local migrationsPath = system.pathForFile("migrations/levels") for migrFilename in lfs.dir(migrationsPath) do -- Read the file and do stuff with it. It doesn't matter for the question end
This code works as it is on an Android device. I had to add the section that says “Read one of the files in the folder”, otherwise the lfs.dir statement would work on the simulator but not on the Android device (would say the folder doesn’t exist). I made a non-live build, installed the .apk as usual.
I wonder why this is behaving in this way. I came with this “solution” by exhaustion, after trying countless things, and it doesn’t make sense at all to me, I shouldn’t need to open a file in the folder before being able to list the files in that folder. This is definitely reading from system.ResourceDirectory, which I know it behaves in a particular way on Android but still weird.
Any insights appreciated.