Page 1 of 1
Getting save directory items
Posted: Tue Jun 30, 2020 2:39 pm
by Hipreme
What I wanted to do is:
Code: Select all
love.filesystem.getDirectoryItems(love.filesystem.getSaveDirectory())
And then get every file that the user has in it save folder, but it does not return anything
Doing
Code: Select all
love.filesystem.getDirectoryItems("")
instead, will return every source file plus the save folder files, how can I manage to get only from save folder?
I've tried passing to "save/" and "saves/" as parameters, but it doesn't seem to work
Re: Getting save directory items
Posted: Tue Jun 30, 2020 10:22 pm
by grump
Best solution is to create a dedicated save directory when your game starts.
In cases where that's not sufficient, you can use
love.filesystem.getRealDirectory to check the real location of each file.
Re: Getting save directory items
Posted: Wed Jul 01, 2020 6:29 am
by zorg
I appreciate the private message, but i'll answer here instead:
The
love.filesystem.getRealDirectory wiki page has an example of what you want to do.
Code: Select all
-- Get all files in the "levels" folder.
-- There might be a "levels" folder in both the save directory and the game's source,
-- in which case this will get all files in both.
local filepaths = love.filesystem.getDirectoryItems("levels")
for i, filename in ipairs(filepaths) do
-- For each filename, check whether it's in the save directory or not.
local path = "levels/"..filename
if love.filesystem.getRealDirectory(path) == love.filesystem.getSaveDirectory() then
-- This file is in the save directory.
end
end
Re: Getting save directory items
Posted: Wed Jul 01, 2020 6:46 pm
by ivan
as grump said you dont need that check at all, just make a unique folder in the save directory. name your folder something useful like the version of your game (in case the save format changes)
Re: Getting save directory items
Posted: Wed Jul 01, 2020 10:15 pm
by zorg
True, but if one doesnt want to do it that way, then it is best to expand on that alt answer... also they private messaged me so i felt like answering here instead, as i already said.