9 Replies Latest reply on Dec 14, 2015 3:59 AM by udayutkarsh

    How to forcefully delete an entire folder ? vifs.pl does not support this feature

    lamw Guru
    Community WarriorsVMware Employees

      I'm trying to delete an entire directory and I was hoping to use RCLI vifs.pl command, but unfortunately even though there is a --force flag in conjunction with --rmdir, it does not allow you to delete a directory if it contain files. I also see that the vifs.pl command does not support listing of files without having to go to dsbrowser.pl (which I'm hoping I don't have to use).


      What is the preferred method of removing an entire directory when passing a parameter of the following "\[datastore\] vm". I wanted to preserve as much of the original default commands within VMware VIMA as possibly without having to include a patch fix or side script


      I was thinking of searching the specified directory and looking at the files and remoing it using vifs.pl ? Though I'm not getting any files being printed out and also how might I handle recursive deletes if the directory contains multiple directories with .vmdk under it?

      my $eBrowser = Vim::get_view (mo_ref => $vm_view->environmentBrowser);
      my $browser = Vim::get_view (mo_ref => $eBrowser->datastoreBrowser);
      my $ds_path = "$TMP_DIR";
      my $file_query = FileQueryFlags->new(fileSize => 0,fileType => 0,modification => 0);
      my $searchSpec = HostDatastoreBrowserSearchSpec->new(details => $file_query,matchPattern => \["*.vmx", "*.vmdk"\]);
      my $search_res = $browser->SearchDatastoreSubFolders(datastorePath => $ds_path,searchSpec => $searchSpec);
      if ($search_res) {
              foreach my $result (@$search_res) {
                      my $files = $result->file;
                              if ($files) {
                                      foreach my $file (@$files) {
                                              #call vifs.pl to remove each file??
                                              print $file,"\n";











      VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/