创建带有文件结构的递归表格。

我想从一个文件夹递归获取文件列表并以表格形式显示。

我尝试了以下内容:

function getStructure ( path )
    local fileArray = readFilesAndFoldersFromPath( path ) -- 返回表格
    for i = 1, #fileArray do
        if fileArray[i].type == 'folder' then
            getStructure ( fileArray[i].path )
        end
    end
end
getStructure( '/folder/example')

这行得通。但现在我也想在一个多维表中得到结果,如下所示:

[1] =>  file1
    =>  file2
[2] =>  folder1
        => file 3
        => file 4
        => folder 2
[3] =>  file 5

如何实现这个目标?

点赞
用户2995502
用户2995502
## 函数定义:获取文件夹结构

```lua
function getStructure(path)
    local fileArray = readFilesAndFoldersFromPath(path) -- 返回表格
    for i = 1, #fileArray do
        if fileArray[i].type == 'folder' then
          fileArray[i].folder_content = getStructure(fileArray[i].path)
        end
    end
    return fileArray
end

调用方式

local myFolderStructure = getStructure('/folder/example')

```

2014-11-02 17:38:24