Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Traversing your project directory with Lua File System
Started by bam14 Jan 02 2016 07:47 PM

- - - - -
1 reply to this topic
lfs directory

Best Answer roaminggamer , 03 January 2016 - 12:22 PM

I believe, that the resource directory (where your app and assets live) does not exist in a traversable format on Android.

 

So, you won't be able to list files and folders there.  You can only give direct paths within your code prior to building.  This is not Corona's fault, but the way Android binaries work.

 

However, since you've already got all of your images and path data when you make your app, simply put that in a table and use that.  i.e. Don't discover the images at run time and you'll be fine.

 

-Ed

 

Note: If you are completely in love with the idea of discovering paths and files, you can also do this:

 

1.Have your app detect whether it is 'in the simulator' or on device.

 

2a. When 'in simulator' discover all paths and files.  

2b. Then, save that info in a file as text or as a JSON encoded table.

2c. Save the file.

 

3. When you go to build, copy that file over to your resource directory and have your app read from it when running on device.

 

Viola!  Discoverable for development, fixed and locateable when running on device.  

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

bam14

[GLOBAL: userInfoPane.html]
bam14
  • Enthusiast

  • 37 posts
  • Corona SDK

Hi all,

 

I am trying to create a little widget that allows the user to cycle through different options, each represented by an image.  To do this, I need to use lfs to search a given directory for images to cycle through.  Here is the code I am using to do this:

 

for file in lfs.dir (path_for_elements) do
     if (file ~= ".") and (file ~= "..") then
          t[i] = path_for_elements..file

          i = i + 1
     end
end

 

This works in the simulator, but not on an Android build.  I am assuming that this is because the file structure is compiled into binary and can't be traversed with the lfs library.

 

Right now, I am working around this by mirroring the structure of my images directory with a table.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

  Best Answer

I believe, that the resource directory (where your app and assets live) does not exist in a traversable format on Android.

 

So, you won't be able to list files and folders there.  You can only give direct paths within your code prior to building.  This is not Corona's fault, but the way Android binaries work.

 

However, since you've already got all of your images and path data when you make your app, simply put that in a table and use that.  i.e. Don't discover the images at run time and you'll be fine.

 

-Ed

 

Note: If you are completely in love with the idea of discovering paths and files, you can also do this:

 

1.Have your app detect whether it is 'in the simulator' or on device.

 

2a. When 'in simulator' discover all paths and files.  

2b. Then, save that info in a file as text or as a JSON encoded table.

2c. Save the file.

 

3. When you go to build, copy that file over to your resource directory and have your app read from it when running on device.

 

Viola!  Discoverable for development, fixed and locateable when running on device.  




[topic_controls]
[/topic_controls]