我正在尝试使用Lua使用scandir函数来扫描根目录。如果我将下面的代码用于任何其他目录,它就能很好地工作。它扫描目录并返回存在的所有文件。
directory="//home//"
function scandir(directory)
local i, t, popen = 0, {}, io.popen
for filename in popen('ls -a "'..directory..'"'):lines() do
i = i + 1
t[i] = filename--loop populates the array with the scanned files
end
print(unpack(t))
return t--t contains all the scanned files
end
scandir(directory)我下面有几个文件
user@user:~/.program$ ls
file1 file2 如何在目录中设置路径,以便它扫描根目录来访问file1和file2??
发布于 2015-07-13 18:22:53
您不能在字符串中转义正斜杠/。要扫描/home,请使用以下命令:
directory = "/home"根直接用一个斜杠表示:
directory = "/"https://stackoverflow.com/questions/31380615
复制相似问题