Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230200

Re: Create a directory tree: How to call a global function from within a for loop

$
0
0

Hello,

The createFolder() method returns the VcFolder object of the folder just created, so the new folder could be used immediately.  Here's how I modified the code:

 

// Create the folderBase level of folders
for (var i=0; i<folderBase.length; i++) {
var newBaseFolder = buildFolderTree(parentFolder, folderBase[i]);
  // Create the folderT1 level of folders
  for (var j=0; j<folderT1.length; j++) {
   var newT1Folder = buildFolderTree(newBaseFolder, folderT1[j]);
    // Create the folderT2 level of folders
    for (var k=0; k<folderT2.length; k++) {
     var newT2Folder = buildFolderTree(newT1Folder, folderT2[k]);
      // Create the folderT3 level of folders
      for (var x=0; x<folderT3.length; x++) {
       var newT3Folder = buildFolderTree(newT2Folder, folderT3[x]);
        // Create the folderT4 level of folders
        for (var y=0; y<folderT4.length; y++) {
         var newT4Folder = buildFolderTree(newT3Folder, folderT4[y]);
        }
      }
    } 
  }
}

function buildFolderTree(parentFolderObj, folderName) {
  System.log("Building folder " + folderName);
  var newFolder = parentFolderObj.createFolder(folderName);
  System.log("Built directory: " + folderName);
  return newFolder;
}

 

 



Viewing all articles
Browse latest Browse all 230200

Trending Articles