Displaying all contents in a folder [help]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
BluBillz
Prole
Posts: 46
Joined: Tue Oct 29, 2013 6:02 pm

Displaying all contents in a folder [help]

Post 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!
pelicano_o
Prole
Posts: 13
Joined: Sun Mar 09, 2014 1:44 am

Re: Displaying all contents in a folder [help]

Post 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
User avatar
BluBillz
Prole
Posts: 46
Joined: Tue Oct 29, 2013 6:02 pm

Re: Displaying all contents in a folder [help]

Post 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?
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Displaying all contents in a folder [help]

Post 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.
User avatar
BluBillz
Prole
Posts: 46
Joined: Tue Oct 29, 2013 6:02 pm

Re: Displaying all contents in a folder [help]

Post by BluBillz »

Alright thanks for the help!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests