How to create a directory in Lua?

后端 未结 4 1027
南旧
南旧 2021-02-19 20:46

Is it possible to create a directory in lua ? If so, how ?

相关标签:
4条回答
  • 2021-02-19 21:12

    There's a "system" call (or something like that, this is from memory) which you should be able to use to run an arbitrary program, which could include the mkdir command.

    EDIT: I found my Programming in Lua book. On page 203, it mentions how you could use an

    os.execute("mkdir " .. dirname)
    

    to "fake" a directory creation command.

    EDIT 2: Take note of Jonas Thiem's warning that this command can be abused if the directory name comes from an untrusted source!

    0 讨论(0)
  • 2021-02-19 21:28

    You can use the paths package instead. Then you can simply do:

    require 'paths'
    
    paths.mkdir('your/dir')
    
    0 讨论(0)
  • 2021-02-19 21:32

    You may find the LuaFileSystem library useful. It has a mkdir function.

    require "lfs"
    lfs.mkdir("/path/to/dir")
    
    0 讨论(0)
  • 2021-02-19 21:33

    You may also want to look at Lua/APR, the Apache Portable Runtime binding for Lua. The docs can be found at here

    One of the reasons I use Lua is that I can write code that runs across multiple OSes. I was using LFS for some time, but have found that using Lua/APR provides a more platform-neutral library. And there are lots of other useful routines in the APR.

    0 讨论(0)
提交回复
热议问题