How read directories?

How read directories?

Im doing a app that can change Themes. To do this, I will put all images in a directory and I’d like to read the directory to check if exist. If its positive, display it in a table with the approprieate name.

So, Ive read the documentation API about implicit and explicit file manipulation, but its not clear for me. Can I read the directoy?

Thanks for any help. [import]uid: 9133 topic_id: 14455 reply_id: 314455[/import]

… [import]uid: 35642 topic_id: 14455 reply_id: 53477[/import]

@bsdrago,
you cannot read the directories per say. But you can work around it if you so want.

you said that you will have themes, where do these themes come from? If you have them all packaged when deployed, then you know the directory structure, but if you are wanting to dynamically download a directory from a webserver or something, then save that folder name in a file as a folder that has been created so you know of them. Almost like create a folder table.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14455 reply_id: 53505[/import]

I just thought was strange have this function:

io.type() if the only type know is “file”

Sometimes we have an idea, but we dont realize how it will work!

Thanks for your sugestion. I’ll try it. :smiley: [import]uid: 9133 topic_id: 14455 reply_id: 53563[/import]

Why don’t you do it dynamically using modules?

directories.lua:

local directories = {  
 {--start of first theme  
  
 images = {  
  
 {image="image1.png" width= "40", height="40"},  
 {image="image2.png" width= "40", height="40"},  
 {image="image3.png" width= "40", height="40"},  
  
 },  
  
 },  
  
 {--start of second theme  
  
 images = {  
  
 {image="image1.png" width= "40", height="40"},  
 {image="image2.png" width= "40", height="40"},  
 {image="image3.png" width= "40", height="40"},  
  
 },  
  
 },  
  
}  
  
return directories  

Then in main.lua have:

  
 local directories = require "directories"   
  

Then to access any image in theme one you would do:

 directories[1].images[i] 

You would need something to control i maybe a for loop that iterates through the size of #images. Change the 1 to 2, or 3 for different themes.

To display the image you would want to do something like:

  
local image = display.newImageRect(directories[1].images[i].image, directories[1].images[i].width, directories[1].images[i].height)  
  

Just typed that here so there might be a few errors.

[import]uid: 87611 topic_id: 14455 reply_id: 54119[/import]