如何在Lua中创建目录?

发布于 2024-08-10 12:50:06 字数 33 浏览 4 评论 0原文

是否可以在 lua 中创建目录?如果是这样,怎么办?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻找我们的幸福 2024-08-17 12:50:07

有一个“系统”调用(或类似的东西,这是来自内存的),您应该能够使用它来运行任意程序,其中可能包括 mkdir 命令。

编辑:我找到了我的Lua编程书。在第 203 页,它提到了如何使用

os.execute("mkdir " .. dirname)

“伪造”目录创建命令。

编辑 2: 请注意 Jonas Thiem 的警告,如果目录名称来自不受信任的来源,则此命令可能会被滥用!

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!

超可爱的懒熊 2024-08-17 12:50:07

您可能会发现 LuaFileSystem 库很有用。它有一个 mkdir 功能。

require "lfs"
lfs.mkdir("/path/to/dir")

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

require "lfs"
lfs.mkdir("/path/to/dir")
北风几吹夏 2024-08-17 12:50:07

您可能还想查看 Lua/APR,Lua 的 Apache Portable Runtime 绑定。这些文档可以在此处找到

我使用 Lua 的原因之一是我可以编写这样的代码跨多个操作系统运行。我使用 LFS 一段时间了,但发现使用 Lua/APR 提供了一个更加平台中立的库。 APR 中还有许多其他有用的例程。

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.

三岁铭 2024-08-17 12:50:07

您可以使用 paths 包代替。然后你可以简单地执行以下操作:

require 'paths'

paths.mkdir('your/dir')

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

require 'paths'

paths.mkdir('your/dir')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文