More filesystem questions

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
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

More filesystem questions

Post by Madrayken »

Hey folks,

In Moonring, I've now changed the data structure in the Love file to have its own SAVE folder, so I can pull files from that as default.
The game still has to create writable directories for the player with the same name in order for this to be useful.

However, when I try using love.filesystem.getInfo, it returns non-null, presumably because the save directory DOES exist... in the love file! Is there any standard way to tell whether the directory that is found exists in the love file or the save directory?

What I am trying to do is create the actual empty save directories if they don't exist, but I can't do that if the tests keep telling me that it already exists!

- Dene
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

Re: More filesystem questions

Post by Madrayken »

I am assuming this is correct?

Code: Select all

local dir = love.filesystem.getRealDirectory(TEMP_PATH)
  local dir2 = love.filesystem.getSaveDirectory()

  if dir ~= dir2 then
    love.filesystem.createDirectory(TEMP_PATH)
  end
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: More filesystem questions

Post by MrFariator »

love.filesystem.createDirectory creates the requested directories. However, if the directories already exist, the function basically does nothing. The return value (boolean) will tell you if the request was a success (created/exists) or not (could not create directory).
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

Re: More filesystem questions

Post by Madrayken »

Oh, so I could have basically not bothered checking! Thanks for that!
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: More filesystem questions

Post by pgimeno »

EAFP (Easer to ask for forgiveness than permission) ;)
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: More filesystem questions

Post by milon »

Madrayken wrote: Sat Nov 04, 2023 9:56 pm Oh, so I could have basically not bothered checking! Thanks for that!
As long as you can guarantee that you have write access to the folder, yes. Otherwise your saves etc will start failing inexplicably.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

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