Loop to a filesystem structure in my object to get all the files

后端 未结 4 1494
孤独总比滥情好
孤独总比滥情好 2021-01-17 01:16

I get a Javascript Object from my server, which depicts a filesystem. Now I want to get the path of all files in the system, e.g. the endpoints of the tree.

File str

4条回答
  •  一个人的身影
    2021-01-17 01:40

    I was busy having a play with your original question and got this working:

    goToDeepestPoint(json);
    
    function goToDeepestPoint(node) {
        if (node.is_dir)
            node.children.forEach(function (child) {
        goToDeepestPoint(child);
    });
        else 
            return out(node.path);
    }
    

    May not be appropriate in the light of your edit, but shame to waste it!

提交回复
热议问题