问题
Is it possible to create a directory in lua ? If so, how ?
回答1:
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!
回答2:
You may find the LuaFileSystem library useful. It has a mkdir function.
require "lfs"
lfs.mkdir("/path/to/dir")
回答3:
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.
回答4:
You can use the paths package instead. Then you can simply do:
require 'paths'
paths.mkdir('your/dir')
来源:https://stackoverflow.com/questions/1690913/how-to-create-a-directory-in-lua