Page 1 of 1

Accessing Files

Posted: Sun Aug 03, 2014 6:22 pm
by Chabidabi
I have a problem accessing files. While the löve filesystem can understand ".." as going up a directory it fails at "../..". Meaning it doesn't list the directory contents of two directories up.

Code: Select all

files = love.filesystem.getDirectoryItems("..");
print(#files);
This outputs the number of files in that directory.

Code: Select all

files = love.filesystem.getDirectoryItems("../..");
print(#files);
This outputs zero.

So do I use the directory name wrong, or is löve restricting my search? And if the latter, what are possible solution to read all files on a system?

Re: Accessing Files

Posted: Sun Aug 03, 2014 7:00 pm
by undef
http://www.love2d.org/wiki/love.filesystem
This module provides access to files in two places, and two places only:

The root folder of the .love archive (or source directory)
The root folder of the game's save directory.
Sorry.

Edit: Or are the subdirectories within those directories as well?

Re: Accessing Files

Posted: Mon Aug 04, 2014 8:51 pm
by T-Bone
If you absolutely must read a file in another folder, you can use Lua's io module. http://www.lua.org/manual/5.1/manual.html#5.7

I wouldn't recommend it though. For most games, reading and writing saves to the save directory using love.filesystem is enough and much easier (and platform independent).

Re: Accessing Files

Posted: Tue Aug 05, 2014 10:14 am
by Chabidabi
T-Bone wrote:I wouldn't recommend it though. For most games, reading and writing saves to the save directory using love.filesystem is enough and much easier (and platform independent).
The main problem is that the user should be able to import their own data. Furthermore the lua io library lacks directory content listing functions. The only way I was able to do that is using io.popen which only works on Linux. There is the probability of me misusing Windows functions, but the lua documentation also says that popen doesn't work in all cases, so I am unsure wether I should use that.

I can imagine a few methods of working around that. The question is, what is the easiest?

Re: Accessing Files

Posted: Tue Aug 05, 2014 2:47 pm
by slime
Chabidabi wrote:The main problem is that the user should be able to import their own data.
One option would be to have a button in the game to open the save directory in their file browser using [wiki]love.system.openURL[/wiki].

Something like this:

Code: Select all

function OpenSaveFolder()
    return love.system.openURL("file://"..love.filesystem.getSaveDirectory())
end
It will only work if the save directory exists (it gets created when the first file or directory is created with love.filesystem.)

Re: Accessing Files

Posted: Tue Aug 05, 2014 3:24 pm
by Chabidabi
slime wrote:One option would be to have a button in the game to open the save directory in their file browser using [wiki]love.system.openURL[/wiki].
Sir, you are a gentleman and a scholar^^. While not the best solution, I think it is sufficient and more important, easy to implement^^.