check and create directories in LUA

  • #1, by sebastianTuesday, 14. June 2016, 21:16 9 years ago
    Hello there,

    I have a LUA question again (yay):
    In my case i have a hotkey for creating screenshots inside the "Screenshots" folder inside the LocalAppDir.
    The problem here: If this directory doesnt exist, creating a screenshot runs into error.
    So i have to check if the folder exist and if not create it before executing the screenshot function.

    Now i found this for creating a directory:
    os.execute("mkdir " .. dirname)
    

    But besides that also found some comments that it's not wise to use the execute function because the command attached to it is implemented different in every operating system and could fail.
    Instead a reference to the LuaFileSystem (https://keplerproject.github.io/luafilesystem//) is given.
    How do i implement it in Visionaire Studio? Is there a way which works out of the box?

    Also, how do i check if a directory exists?

    kind regards
    Sebastian


    smile

    Thread Captain

    2346 Posts


  • #2, by afrlmeTuesday, 14. June 2016, 22:07 9 years ago
    We can't implement third party plugins. If we could then I would be taking a lot of the Lua modules from Love2d engine & banging them into VS. grin

    You could have it create the folders during installation, that would be the simplest solution. I'm not sure why there isn't a better solution for creating folders with Lua script.

    Imperator

    7285 Posts

  • #3, by sebastianTuesday, 14. June 2016, 22:32 9 years ago
    You could have it create the folders during installation, that would be the simplest solution.

    Does it do it automatically? I cant see a setting on the build game dialog...

    Thread Captain

    2346 Posts

  • #4, by afrlmeWednesday, 15. June 2016, 00:09 9 years ago
    No... I mean whatever game installer you use to pack your game up with, whether it's a custom one, steam, gog or something else. You should be able to include / write to specific directories with it - at least I should assume so.

    Ideally you should probably save screenshots into a folder they can easily access, such as documents or the game root folder, saving them to localAppDir doesn't make much sense as you don't really want the players going into those folders & it's unlikely they'd even think to check there anyway, as not everyone is tech savvy or know that their computers contain hidden folders.

    Imperator

    7285 Posts

  • #5, by sebastianMonday, 20. June 2016, 18:22 9 years ago
    Thanks for the information. I guess i have to distributore the folders while installing the game. I dont know how i will do it on mac because mostly Installations are "copy&paste" the app into the applicationsfolder.

    Thread Captain

    2346 Posts

  • #6, by afrlmeMonday, 20. June 2016, 18:39 9 years ago
    Sorry I can't help you with the mac. I have one, but I'm mostly a windows user.

    Can you not use the local documents folder instead or even a folder inside of the path where the game is installed to? Either of those would be a lot easier than trying to create & check if a folder in user, local blah blah whatever exists.

    Imperator

    7285 Posts

  • #7, by sebastianMonday, 20. June 2016, 18:42 9 years ago
    Yeah, i know. I will find a way as allways razz
    Thanks so far.

    Thread Captain

    2346 Posts