[solved] why does love.filesystem.getInfo return nil on a file that is definitely there?

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
MWTab
Prole
Posts: 6
Joined: Sat Nov 04, 2023 10:13 pm
Location: Salem, Or, USA
Contact:

[solved] why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by MWTab »

Hiya,

I'm writing a love2d starter template for blind accessible games, and I just got my screen reader c library working from within the .love file by copying it to the save directory... However:

I tried to make the template only copy the file(s) if they weren't already there, but that doesn't seem to be working. I do some code like this:

Code: Select all

        if love.filesystem.getInfo(love.filesystem.getSaveDirectory() .. "/" ..
                                       libName) == nil then -- The file doesn't exist, we need to copy it
            -- Fixme, probably should do sanity checks like size, etc, but this will do for now.
            print(love.filesystem.getSaveDirectory() .. "/" .. libName ..
                      " not found...")
            local content = love.filesystem.read(libName)
            love.filesystem.write(libName, content)
        end
        
However, even after the first time of copying the library, getInfo still returns nil, causing it to be copied on every startup. Any idea why this might be? Maybe it doesn't like me using a full path or... something?

Thanks,

-Michael.

P.S. If you want to see the whole project go here: https://git.2mb.codes/~lilmike/love2d-template
Last edited by MWTab on Mon Nov 06, 2023 2:25 pm, edited 1 time in total.
Michael T, creator of blind accessible games for all

My website: https://2mb.games

My sourcecode repositories: https://git.2mb.codes/~lilmike
User avatar
BrotSagtMist
Party member
Posts: 614
Joined: Fri Aug 06, 2021 10:30 pm

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by BrotSagtMist »

Löve was not made for users to deal with files manually.
If you want to defeat the two folders seen as one structure by using relative paths you will just end up with the worst mess of code.

A far easier solution is to simply not use the same name or place for the file.
obey
MWTab
Prole
Posts: 6
Joined: Sat Nov 04, 2023 10:13 pm
Location: Salem, Or, USA
Contact:

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by MWTab »

Ok, I will try that.

-Michael.
Michael T, creator of blind accessible games for all

My website: https://2mb.games

My sourcecode repositories: https://git.2mb.codes/~lilmike
MWTab
Prole
Posts: 6
Joined: Sat Nov 04, 2023 10:13 pm
Location: Salem, Or, USA
Contact:

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by MWTab »

That worked like a charm. Moved my shared libraries under a subdirectory in my .love file and copied them with no subdirectory :-).

-Michael.
Michael T, creator of blind accessible games for all

My website: https://2mb.games

My sourcecode repositories: https://git.2mb.codes/~lilmike
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by slime »

The reason it returned nil in your code is getInfo (and almost every other love.filesystem API) doesn't take full paths, only relative ones. All relative paths in love.filesystem are relative to both the game's source and save directories.

Another way to achieve what you want could be to check what love.filesystem.getRealDirectory returns for the library file, if it has the same relative path in the source and save directories.
MWTab
Prole
Posts: 6
Joined: Sat Nov 04, 2023 10:13 pm
Location: Salem, Or, USA
Contact:

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by MWTab »

Thanks for the pointers. I believe I've solved it ok now, and it even makes my git repo a bit cleaner :D but I'll definitely keep your tips in mind for future use :-).

Btw, is there a way to mark this topic solved?

-Michael.
Michael T, creator of blind accessible games for all

My website: https://2mb.games

My sourcecode repositories: https://git.2mb.codes/~lilmike
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Post by pgimeno »

MWTab wrote: Sun Nov 05, 2023 9:21 pm Btw, is there a way to mark this topic solved?
By editing the first post and changing the topic.
Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests