2017-09-28 42 views
1

Adob​​e After Effectsのextendscript関数では、以下のようなファイルパスのリストをツリービューに変換する必要があります。ここまでは私のコードですが、それは最初の "レベル"の罰金を歩いていますが、私は再帰に問題があります。助けが大変ありがとうございます、私はこれに対して私の頭を打っていて、まだそれを働かせるように見えません!extendscriptのパスから再帰的にツリービューを作成する

{ 
    //----| Build UI 
    var stImporterWin = new Window("palette", "ST Import Panel", undefined, {resizeable:true}); 
     stImporterWin.orientation = "column"; 

    var imageSequenceGroup = stImporterWin.add("group"); 
      imageSequenceGroup.alignment = ["fill", "fill"]; 
      imageSequenceGroup.orientation = "column"; 
      var imageSequenceTree = imageSequenceGroup.add("treeview"); 
       imageSequenceTree.preferredSize = [600,650]; 
       imageSequenceTree.alignment = ["fill", "fill"]; 


    stImporterWin.onResize = function() { 
     this.layout.resize(); 
    } 

    stImporterWin.show(); 

    filesArray = ["//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image2_0001.txt", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image3.0001.txt", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image_001.txt", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/0040-Major Trans M13_Logo_v02.xml", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/Thumbs.db", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/Thumbs.db", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/T1/Thumbs.db", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/Thumbs.db", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png", 
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png"]; 

    rootFolder = File("//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders"); 

    var node0 = imageSequenceTree.add("node", rootFolder.fsName.replace(/\\/g, "/")); 
    node0.expanded = true; 

    //build out arrays from the files 
    for (var i = 0; i < filesArray.length; i++) { 
     filesArray[i] = filesArray[i].split("/"); 
    } 

    //recursive tree building 
    var rootAsArray = rootFolder.fsName.replace(/\\/g, "/").split("/"); 
    BuildChildNodes(rootAsArray, filesArray, node0, 0); 


    // for debug purposes I added "killme" so that we only recurse once for now 
    function BuildChildNodes (root, files, parentNode, killme) { 
     alert("Root: " + root.join("/")); 
     previousDirName = ""; 

     for (var i = 0; i < files.length; i++) { 
      var currentPath = files[i]; 

      if (currentPath.length > root.length+1) { 
       // we got a sub-folder so add it to the tree if unique and recurse 
       var dirName = currentPath[root.length]; 
       if (dirName != previousDirName) { 
        var newNode = parentNode.add("node", dirName); 
        newNode.expanded = true; 
        previousDirName = dirName; 

        // recurse 
        var newRoot = currentPath.slice(0, root.length+1); 
        var newFilesList = files.slice(i); 
        //make sure we only get this dir 
        for (var j = 0; j < newFilesList.length; j++) { 
         if (newFilesList[j].slice(0, root.length+1).join("/") != newRoot.join("/")) { 
          newFilesList = newFilesList.slice(0,j); 
          break; 
         } 
        }; 

        if (killme == 0) { 
         alert("recursing " + newRoot.join("/")); 
         BuildChildNodes(newRoot, newFilesList, newNode, 1); 
        } 

       } 
      } else { 
       // we got a file in this dir, add it to the tree 
       var fileName = currentPath[root.length]; 
       var newNode = parentNode.add("item", fileName); 
      }  
     } 
    } 
} 

およびサンプル入力リストは次のようになります。上記の最後で

//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image2_0001.txt 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image3.0001.txt 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image_001.txt 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/0040-Major Trans M13_Logo_v02.xml 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/Thumbs.db 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/Thumbs.db 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/T1/Thumbs.db 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/Thumbs.db 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png 
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png 

は、次のようになります。

//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/ 
    test image2_0001.txt 
    test image3.0001.txt 
    test image_001.txt 
    Logo/ 
     0040-Major Trans M13_Logo_v02.xml 
     T1/ 
      0040-Major Trans M13_01_logo_.AO.0000.png 
      0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png 
      0040-Major Trans M13_01_logo_.RGB_color.0000.png 
      0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png 
      0040-Major Trans M13_01_logo_.VRaySpecular.0000.png 
      0040-Major Trans M13_01_logo_.VRayZDepth.0000.png 
      0040-Major Trans M13_01_logo_.origRGB.0000.png 
      Thumbs.db 
     T2/ 
      0040-Major Trans M13_logo_02.0080.png 
      Thumbs.db 
      AO/ 
       0040-Major Trans M13_logo_02._AO0080.png 
      VRaySelfIllumination/ 
       0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png 
      VRaySpecular/ 
       0040-Major Trans M13_logo_02._VRaySpecular0080.png 
      VRayZDepth/ 
       0040-Major Trans M13_logo_02._VRayZDepth0080.png 
    T1/ 
     Thumbs.db 
    Text/ 
     T1/ 
      0040-Major Trans M13_01_text_.AO.0000.png 
      0040-Major Trans M13_01_text_.MultiMatteElement.0000.png 
      0040-Major Trans M13_01_text_.RGB_color.0000.png 
      0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png 
      0040-Major Trans M13_01_text_.VRaySpecular.0000.png 
      0040-Major Trans M13_01_text_.VRayZDepth.0000.png 
      0040-Major Trans M13_01_text_.origRGB.0000.png 
      Thumbs.db 
     T2 ext/ 
      NY18_MajorTrans Ext_01_M13_text..AO.0000.png 
      NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png 
      NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png 
      NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png 
      NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png 
      NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png 
      NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png 

答えて

0

私は再帰を除去することによって、あなたのコードを少し単純化。あなたが階層を歩いていないので必要ありません。各パスに階層があります。

enter image description here

{ 
    //----| Build UI 
    var stImporterWin = new Window("palette", "ST Import Panel", undefined, {resizeable:true}); 
    stImporterWin.orientation = "column"; 

    var imageSequenceGroup = stImporterWin.add("group"); 
    imageSequenceGroup.alignment = ["fill", "fill"]; 
    imageSequenceGroup.orientation = "column"; 
    var imageSequenceTree = imageSequenceGroup.add("treeview"); 
    imageSequenceTree.preferredSize = [600,650]; 
    imageSequenceTree.alignment = ["fill", "fill"]; 


    stImporterWin.onResize = function() { 
     this.layout.resize(); 
    } 

    stImporterWin.show(); 

    filesArray = ["//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image2_0001.txt", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image3.0001.txt", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image_001.txt", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/0040-Major Trans M13_Logo_v02.xml", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/Thumbs.db", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/Thumbs.db", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/T1/Thumbs.db", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/Thumbs.db", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png", 
     "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png"]; 

    rootPath = "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders"; 

    var node0 = imageSequenceTree.add("node", rootPath); 
    node0.expanded = true; 

    //recursive tree building 
    var rootAsArray = rootPath.split("/"); 

    //build out arrays from the files 
    var subFilesArray = []; 
    for (var i = 0; i < filesArray.length; i++) { 
     var split = filesArray[i].split("/"); 
     subFilesArray[i] = split.slice(rootAsArray.length, split.length); 
    } 

    BuildChildNodes(subFilesArray, node0); 

    function BuildChildNodes(subPaths, rootNode) { 
     for (var i=0; i<subPaths.length; i++) { 
     var subPath = subPaths[i]; 
     var curr = rootNode; 

     for (var j=0; j<subPath.length-1; j++) { 
      var path = subPath[j]; 
      var node = getItem(curr, path); 

      if (node) { 
       curr = node; 
      } else { 
       curr = curr.add("node", path); 
      } 
     } 

     curr.add("item", subPath[subPath.length-1]); 
     } 
    } 

    function getItem(node, text) { 
     for (var i=0; i<node.items.length; i++) { 
     var item = node.items[i]; 
     if (item.text === text) { 
      return item; 
     } 
     } 
     return null; 
    } 
} 
+0

恐ろしい:

は、ここでの結果です!これは完璧です、私はちょうどそれで複雑すぎていたと思います! – Spencer

関連する問題