Hello everyone, I got a problem.
So, I need to load files from the folder where .love file is located, so I used love.filesystem.getWorkingDirectory() to get the directory, but this command only returns user directory as love.filesystem.getUserDirectory() command would do.
So, I tried some other ways such as os.execute('dir > tmp.txt'), but it still returns all the files that are in the user directory.
My game is located at: "C:/Documents and Settings/Admin/Рабочий Стол"
I've tried moving my working directory to "C:/" but still love.filesystem.getWorkingDirectory() keep returning me "C:/Documents and Settings/Admin"
Please, help me!
Edit: My apologise, I've re-read what love.filesystem.getWorkingDirectory() command do, and it returns current working directory, sorry, I'm plain dumb.
But there still a problem, how do I return path to the directory where .love file is located?
love.filesystem.getWorkingDirectory returns user directory
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: love.filesystem.getWorkingDirectory returns user directo
I think you should be able to access files which are in the same folder as your .love with io
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: love.filesystem.getWorkingDirectory returns user directo
It returns the working directory, as it says. Now, your problem seems to be that you expect that to be the folder your .love is in, it's generally not. (And the io library uses the working directory as a base, btw.)
Re: love.filesystem.getWorkingDirectory returns user directo
So is there no way to get directory where .love file located? Please, I really need it.
Re: love.filesystem.getWorkingDirectory returns user directo
https://love2d.org/wiki/love.filesystem
https://love2d.org/wiki/love.filesystem
So, to read a file located in /folder from your current directory (ie "C:/Documents and Settings/Admin/Рабочий Стол/folder/tmp.txt") you would do this:Files that are opened for read will be looked for in the save directory, and then in the .love archive (in that order). So if a file with a certain filename (and path) exist in both the .love archive and the save folder, the one in the save directory takes precedence.
Code: Select all
exists = love.filesystem.exists("folder/tmp.txt")
if (exists) then
for lines in love.filesystem.lines("folder/tmp.txt") do
-- do stuff here
end
end
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: love.filesystem.getWorkingDirectory returns user directo
There's no need to get the current dir, just do what MPQC said if you want to load a file from the local dir you just need to type the name of the file.
Hope that helped
Hope that helped
Re: love.filesystem.getWorkingDirectory returns user directo
That won't work if you package your game into a .love, since love.filesystem only looks inside the .love, not in the folder containing the .love. To my knowledge, there's no obvious way to do that.MPQC wrote:https://love2d.org/wiki/love.filesystem
So, to read a file located in /folder from your current directory (ie "C:/Documents and Settings/Admin/Рабочий Стол/folder/tmp.txt") you would do this:Files that are opened for read will be looked for in the save directory, and then in the .love archive (in that order). So if a file with a certain filename (and path) exist in both the .love archive and the save folder, the one in the save directory takes precedence.
https://love2d.org/wiki/love.filesystemCode: Select all
exists = love.filesystem.exists("folder/tmp.txt") if (exists) then for lines in love.filesystem.lines("folder/tmp.txt") do -- do stuff here end end
I guess one option is to not package your game into a .love, and create a script (.bat file on Windows) for starting the game. An alternative solution that may or may not work is to create a script that before launching the game changes the current working directory to wherever you want it to be.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: love.filesystem.getWorkingDirectory returns user directo
If someone is still interested, I think I have the solution.
Try love.arg.options.game.arg[1], it works for me (I don't know whether it exists for all Löve versions ; I'm on 0.9.1).
It is not a function : it's directly the value, stored as a string.
Try love.arg.options.game.arg[1], it works for me (I don't know whether it exists for all Löve versions ; I'm on 0.9.1).
It is not a function : it's directly the value, stored as a string.
Code: Select all
print(love.arg.options.game.arg[1])
-- it prints a path like "/home/user/thing/stuff.love"
Re: love.filesystem.getWorkingDirectory returns user directo
Interesting. How on Earth did you find out about that?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: love.filesystem.getWorkingDirectory returns user directo
In newer love versions you can access the directory your fused game is in by mounting it, therefore love contains [wiki]love.filesystem.getSourceBaseDirectory[/wiki] to find that directory and [wiki]love.filesystem.mount[/wiki] to mount it.
Who is online
Users browsing this forum: No registered users and 2 guests