Reputation: 110
I am making a project with lua that gets a list of all the file names from your desktop in lua. however, I can't figure out how to do it, and I am also going to be using love2d for it, because it is going to be a game. can you tell me how to do it? thanks!
Here is the code
function love.load()
require "player"
-- Lets add Some Variables!
-- Some Directory Suff first for Variables...
DesktopDirectory = love.filesystem.getUserDirectory().."Desktop"
DesktopFiles = love.filesystem.getDirectoryItems(DesktopDirectory)
-- These are the Images!
images = {
background = love.graphics.newImage("gfx/desktop.png")
}
players = {Player.New(50, 300, 40, 40, "gfx/stickman.png", true)}
love.graphics.setBackgroundColor(100, 220, 255)
for k in pairs(DesktopFiles) do
print(DesktopFiles[k])
end
end
function love.keypressed(k)
if k == "j" then
players[1].jump()
end
end
function love.update(dt)
for i in pairs(players) do
players[i].update()
end
end
function love.draw()
love.graphics.draw(images.background)
for i in pairs(players) do
players[i].draw()
end
end
Upvotes: 1
Views: 590
Reputation: 4264
Love2D (tries to) sandbox file system access, you're not supposed to touch anything outside your game's code or the "save directory" (where anything that you write goes). In particular, the Desktop folder is also out of reach. If you try to use love.filesystem.getDirectoryItems
on that path, you'll just get an empty table. Same for other functions – they'll just refuse to work.
The easiest way to get that functionality is to include lfs
and use its functions together with Lua's base io
library for general file system access.
Upvotes: 3