2014-11-01 2 views
0

테이블에서 폴더의 파일 목록을 재귀 적으로 가져 오려고합니다. 작동파일 구조가있는 재귀 테이블 만들기

function getStructure (path) 
    local fileArray = readFilesAndFoldersFromPath(path) -- returns table 
    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 

어떻게 수행할까요?

답변

0
function getStructure (path) 
    local fileArray = readFilesAndFoldersFromPath(path) -- returns table 
    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') 
관련 문제