Accessing Files

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
Chabidabi
Prole
Posts: 3
Joined: Sun Aug 03, 2014 5:51 pm

Accessing Files

Post 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?
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: Accessing Files

Post 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?
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Accessing Files

Post 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).
Chabidabi
Prole
Posts: 3
Joined: Sun Aug 03, 2014 5:51 pm

Re: Accessing Files

Post 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?
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Accessing Files

Post 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.)
Chabidabi
Prole
Posts: 3
Joined: Sun Aug 03, 2014 5:51 pm

Re: Accessing Files

Post 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^^.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests