Page 1 of 1

Displaying all contents in a folder [help]

Posted: Fri Apr 03, 2015 8:17 am
by BluBillz
Hello I have been trying to figure out how I could exactly display all the content inside a specific folder. What I am trying to do is simply show inside love all of the images inside of a specific folder without me having to code in each image inside that folder. Would anyone know how exactly i could do something like this?

On another note..When trying to actually display all of the images...I want it displayed in a row so with that being said when you do love.graphics.draw(), at the X would I do something like...

Code: Select all

love.graphics.draw(images,images.x+images.x+10,0)
For it to display it after each image without them being in a bunch? I hope this part makes sense its the best way I can word it lol.

Any help with this would be great!

Re: Displaying all contents in a folder [help]

Posted: Fri Apr 03, 2015 1:58 pm
by pelicano_o
I think this will help.
https://love2d.org/wiki/love.filesystem ... ctoryItems
I would use love.filesystem.getDirectoryItems() to store the names of the images in a table.
Then iterate through each item of the table to create the corresponding image objects in another table.
Something like:

Code: Select all

ImageNames = love.filesystem.getDirectoryItems( "Images" )
Images = {}
for i = 1, #ImageNames do
	local path = "Images/" .. ImageNames[i]
	Images[i] = love.graphics.newImage(path)
end
To display images in a row, just iterate through the Image table to draw each item.

Code: Select all

for i,v in ipairs(Images) do
	love.graphics.draw(v, 10 + i*100)
end

Re: Displaying all contents in a folder [help]

Posted: Fri Apr 03, 2015 5:44 pm
by BluBillz
pelicano_o wrote:I think this will help.
https://love2d.org/wiki/love.filesystem ... ctoryItems
I would use love.filesystem.getDirectoryItems() to store the names of the images in a table.
Then iterate through each item of the table to create the corresponding image objects in another table.
Something like:

Code: Select all

ImageNames = love.filesystem.getDirectoryItems( "Images" )
Images = {}
for i = 1, #ImageNames do
	local path = "Images/" .. ImageNames[i]
	Images[i] = love.graphics.newImage(path)
end
[/quote]


Thanks for showing me about love.filesystem.getDirectoryItems, but i am actually using love2D version 0.8

That only is working for version 0.9, what would be an alternative for love.filesystem.getDirectoryItems for version 0.8?

EDIT* I found love.filesystem.enumerate, would this be what I would want for version 0.8?

Re: Displaying all contents in a folder [help]

Posted: Fri Apr 03, 2015 6:58 pm
by Jasoco
Just something you need to keep an eye out for when dealing with loading things from an enumerated file list of a folders contents is to discard any hidden or non-qualifying file types. If you're only loading images you can check to make sure the extension is PNG, JPG or whatever you need. Or if you want to list all the files for a user to view, make sure to exclude any system hidden files like Windows Thumbs.db or Desktop.ini or OS X's .DS_store files, etc. These are files you won't see by default in the Explorer or Finder but the OS creates to store settings for viewing that folders contents. Löve won't be able to do anything with them much but can error out if you accidentally try to load one as a .lua or image.

Re: Displaying all contents in a folder [help]

Posted: Sat Apr 04, 2015 12:11 am
by BluBillz
Alright thanks for the help!