os.execute("mkdir Dir") not working on Mac

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
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

os.execute("mkdir Dir") not working on Mac

Post by OmarShehata »

So I have a launcher for my game. This launcher downloads the game's files, and automatically looks for and downloads updates. The launcher is written in love.

In order to do that, I need to be able to write files outside of the launcher.love, so I can't use love's filesystem. I simply use Lua's io library.

In order to create directories, I need to run os.execute("mkdir Dirname"), which works perfectly on Windows, but for some reason, I can't get it to work on Mac at all.

No errors, it just doesn't create the directory. I had a suspicion that I just wasn't directing the correct directory, but even when entering the full path to the folder that the launcher.love is in by doing:

Code: Select all

os.execute("cd Full/Path/To/My/Folder && mkdir Dirname")
Still, nothing. Can anybody create a directory in this way on Mac?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: os.execute("mkdir Dir") not working on Mac

Post by Nixola »

If you get files inside the save folder and they're named as the ones inside the .love (or .exe), require and love.filesystem will read the former ones, so you could save your files there... It doesn't solve the issue you're having, but maybe you don't have to do it that way
Also, did you try "mkdir /full/path/to/folder"?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: os.execute("mkdir Dir") not working on Mac

Post by davisdude »

PiL 22.2 wrote:For instance, both in Unix and in DOS-Windows, you can write the following function to create new directories:

Code: Select all

function createDir (dirname)
     os.execute("mkdir " .. dirname)
end
The os.execute function is powerful, but it is also highly system dependent.
That being said, I can't find anything about doing it on Mac, but...
Good luck! :)
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
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by OmarShehata »

I know os.execute is highly system dependent, but all it does is run a command as if you typed it in the terminal/cmd right?

So if the exact same command works when I type it in the terminal on Mac, it should theoretically work from Lua as well, if I understand correctly.

And Nixola, I could very well download the files in the save directory and it will all be well and nice, but the only reason we want it to download in the current directory is so that folders like "Levels" and "Mods" are easily accessible to people without them having to navigate to an obscure folder on their system. To just copy/paste or share levels like that.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: os.execute("mkdir Dir") not working on Mac

Post by Nixola »

You could use os.execute to open that folder for them in a window, like Minecraft does:

Code: Select all

function openFolder(path)
  if love.os == "Windows" then
    os.execute("start "..path)
  elseif love.os == "Linux" then
    os.execute("xdg-open "..path)
  elseif love.os == mac then --I don't know what it's like here
    os.execute() --beats me
  end
end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by kikito »

OmarShehata wrote:the only reason we want it to download in the current directory is so that folders like "Levels" and "Mods" are easily accessible to people without them having to navigate to an obscure folder on their system. To just copy/paste or share levels like that.
May I suggest creating a symbolink link to the folder in question, probably when the game installs, as an alternative? That way you can use love.filesystem and at the same time your users have it easy.
When I write def I mean function.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by slime »

OmarShehata wrote:the only reason we want it to download in the current directory is so that folders like "Levels" and "Mods" are easily accessible to people without them having to navigate to an obscure folder on their system. To just copy/paste or share levels like that.
You could have a button in-game which opens the folder in the user's file browser. Here's a function which can do that.

You would also be able to have levels and mods distributed and placed as zip files (maybe even with a custom extension if you want), and read by love.filesystem with [wiki]love.filesystem.mount[/wiki].

It's also possible to use love.filesystem.mount to essentially replace game files with updated ones completely from inside love.filesystem, if for example you downloaded an updated .love (or .zip containing the files) to the save directory and then did love.filesystem.mount("updatedgame.love", "").
[If you don't want files in mounted archives taking precedence over files in the actual game source, the optional third argument to mount can change that - or you could use something other than an empty string for the second argument.]
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by OmarShehata »

kikito wrote:May I suggest creating a symbolink link to the folder in question, probably when the game installs, as an alternative? That way you can use love.filesystem and at the same time your users have it easy.
I am liking this idea. But how would I go about doing that? I'm guessing the installer would have to be something other than Love?

I didn't know I could read zip files like that, that's pretty cool!

I think that alternative will definitely save us a lot of headaches, placing the game's folders and files in the save directory and letting the user open it with a button in-game. I could even still write files in the current directory, like startup.ini.

There is another alternative. What about LuaFileSystem? Since I'm preparing slightly tweaked versions for each OS anyway, I might as well include the necessary LFS library with it. Only problem would be building it for Mac and Linux, (I don't have any experience building stuff from the source, I found a windows lfs.dll)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by bartbes »

Symbolic links are not followed by default, but I guess if you really wanted to you might be able to talk the luajit ffi into enabling it for you.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: os.execute("mkdir Dir") not working on Mac

Post by kikito »

OmarShehata wrote: I am liking this idea. But how would I go about doing that? I'm guessing the installer would have to be something other than Love?
Yes, the installer would have to be something other than LÖVE. It can be something as simple as a install.sh for mac & linux and a install.bat for windows. Of course there are more elaborate things. There're installers for windows (I have not used any), mac has a thing called "Pkg maker" and linux has .debs and .rpms and all the other crazy package installers.
bartbes wrote:Symbolic links are not followed by default, but I guess if you really wanted to you might be able to talk the luajit ffi into enabling it for you.
I was suggesting making a link on the "easy part for the user" (like, next to the executable) pointing to the "easy part for LÖVE" (the save folder). Users can double click, and LÖVE doesn't have to deal with symlinks at all.
When I write def I mean function.
Post Reply

Who is online

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