This is not working for me. Folders are present only in relative_path attribute (which starts with dc name), and this line is overridding it. As such this can work only if the VM to be cloned is in /.
This is working for me :      
     <code>dc_replace = /#{datacenter}\//
      vm.relative_path = vm.folder.path.gsub(path_replace, '')+vm.relative_path.gsub(dc_replace,'')</code>