Getting save directory items

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
Hipreme
Prole
Posts: 12
Joined: Wed Jun 03, 2020 9:57 pm
Contact:

Getting save directory items

Post by Hipreme » Tue Jun 30, 2020 2:39 pm

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

grump
Party member
Posts: 612
Joined: Sat Jul 22, 2017 7:43 pm

Re: Getting save directory items

Post by grump » Tue Jun 30, 2020 10:22 pm

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.

User avatar
zorg
Party member
Posts: 2918
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Getting save directory items

Post by zorg » Wed Jul 01, 2020 6:29 am

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
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
ivan
Party member
Posts: 1561
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Getting save directory items

Post by ivan » Wed Jul 01, 2020 6:46 pm

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)

User avatar
zorg
Party member
Posts: 2918
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Getting save directory items

Post by zorg » Wed Jul 01, 2020 10:15 pm

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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests