Searching subdirectory for files

I’m trying to loop through and load all of my images in my sub directory “images”.

I’m using the following code.

[lua]

local basePath = “images/”

local directory = system.ResourceDirectory

local doc_path = system.pathForFile( basePath, directory )

print(doc_path)

for file in lfs.dir( doc_path ) do

–display and hide graphics

print(file)

end

[/lua]

This code was working fine on my windows computer but on my mac I get the following error.

Jan 23 01:34:51.523: ERROR: The resource file (images) could not be found at case-sensitive path (/Users/Downhill Dash 16.01.23/images).

Jan 23 01:34:51.524: WARNING: Cannot create path for resource file ‘images’. File does not exist.

You’re going to run into issues trying to search and iterate over files in the ResourceDirectory.  You should not do that as it simply won’t work on Android, can’t be written to on either Android or iOS, and may not be allowed on OS X / Windows desktop builds due to permissions settings on the target machine.

Short answer: Generally, you should not attempt to do dynamic coding where you iterate the contents of the resource directory.  It mostly will not work as expected.

The only areas you can consistently search, write, delete, etc. in are ‘documents’ and ‘temporary’.

You’re going to run into issues trying to search and iterate over files in the ResourceDirectory.  You should not do that as it simply won’t work on Android, can’t be written to on either Android or iOS, and may not be allowed on OS X / Windows desktop builds due to permissions settings on the target machine.

Short answer: Generally, you should not attempt to do dynamic coding where you iterate the contents of the resource directory.  It mostly will not work as expected.

The only areas you can consistently search, write, delete, etc. in are ‘documents’ and ‘temporary’.