Page 1 of 1

[solved] problem with the path from getSaveDirectory

Posted: Sat Mar 21, 2015 5:04 pm
by Dudenheit
Hi,

I tried to read some files at start, which are saved in the standard-save-directory of love2d. The directory exists and I managed to write some file there, also.
The files are known by the engine, for example with this code from the wiki:

Code: Select all

	local dir = ""
	local files = love.filesystem.getDirectoryItems(dir)
	for k, file in ipairs(files) do
    	print(k .. ". " .. file) --outputs something like "1. main.lua"
	end
all file-names (of the save-directory AND of the directory, where the main.lua-file is) are listed in the console.

Now I wanted (as I need) the files only, which are in the save-directory.
I tried

Code: Select all

local str_path = "file://"..love.filesystem.getSaveDirectory()
and

Code: Select all

local str_path = love.filesystem.getSaveDirectory()
but both paths do not exist?
(I tested this with love.filesystem.exists, which returns a true or false)
Is there a hint, how I could handle this? Is there a problem with the paths if I use windows (instead of linux?) My username has no "special" characteres...

Thanks for reading so far :-)

EDIT: Solved, thanks a lot!!

Re: problem with the path from getSaveDirectory

Posted: Sat Mar 21, 2015 5:36 pm
by Robin
Currently there is no way to do this, because PhysFS doesn't tell LÖVE where it gets the files it finds.

Re: problem with the path from getSaveDirectory

Posted: Sat Mar 21, 2015 6:03 pm
by undef
I ran into the same Problem the other day.
I wanted to delete all the Data in the save directory, and I got it working - but not without calling love.filesystem.remove for every file in the game directory as well...

Re: problem with the path from getSaveDirectory

Posted: Sat Mar 21, 2015 7:28 pm
by bartbes
If you do need to separate content, you could make it identifiable, for instance by putting it in a (different) subdirectory.

Re: problem with the path from getSaveDirectory

Posted: Sat Mar 21, 2015 9:05 pm
by slime
You could use [wiki]love.filesystem.getRealDirectory[/wiki], like so:

Code: Select all

for i, filename in ipairs(love.filesystem.getDirectoryItems(folder)) do
    local filepath = folder.."/"..filename

    if love.filesystem.getRealDirectory(filepath) == love.filesystem.getSaveDirectory() then
        -- The file is in the save directory.
    end
end