从Lua中的目录获取文件名 [英] Getting a file name from directory in Lua
本文介绍了从Lua中的目录获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从Lua中的目录中获取文件名.
I need to get the file name from a directory in a Lua.
我不想使用require "lfs"
.
使用popen/open会有所帮助.
Using popen / open would be helpful.
推荐答案
Specifically the following can be modified to do what you want:
local dircmd = "find . -type f -print" -- default to Unix
if string.sub(package.config,1,1) == '\\' then
-- Windows
dircmd = "dir /b/s"
end
os.execute(dircmd .. " > zzfiles")
local luafiles = {}
for f in io.lines("zzfiles") do
if f:sub(-4) == ".lua" then
luafiles[#luafiles+1] = f
end
end
print(table.concat(luafiles, "\n"))
这篇关于从Lua中的目录获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文