Every so often you have nested folders in a vCenter and want to return only the top level folder. Here is a function to return the top level folder only:
function return_folder_path(vm) { var parent = vm.parent; var parentNames = new Array(); var vmPathName = ""; while (parent instanceof VcFolder){ parentNames.push(parent.name); parent = parent.parent; } for (i=(parentNames.length-2); i>=0; i--){ //vmPathName += "/"+parentNames.pop(); vmPathName += "/"+parentNames[i]; } return vmPathName; }