Hi every one, this is my problem: I need to browse a datastore and discover all the empty folders, the problem is that browser.searchDatastoreSubFolders_Task(path, hdbss) seems to be ignoring empty folders even using FolderFileQuery, maybe this is not the right browsing method for my particular problem? any ideas?
Thank you a lot, any suggestion is very welcome.
That is the correct method to use, I've not specifically tried to search for "empty folders", but you should get a return of all folders under a given path. What language are you implementing this search in? Can you provide the code snippet that you're currently using to search for empty folders?
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Thank you a lot for your quick answer!,
maybe its worth to mention that I'm using VI Java
Alright the code would be like this:
... HostDatastoreBrowser browser = datastore.getBrowser(); HostDatastoreBrowserSearchSpec hdbss = new HostDatastoreBrowserSearchSpec(); hdbss.setSearchCaseInsensitive(false); hdbss.setSortFoldersFirst(true); hdbss.setQuery(new FileQuery [] {new FolderFileQuery()}); Task task = browser.searchDatastoreSubFolders_Task("[esx_local_storage]", hdbss); task.waitForTask(); object = task.getTaskInfo().getResult(); ArrayOfHostDatastoreBrowserSearchResults result = (ArrayOfHostDatastoreBrowserSearchResults) object; HostDatastoreBrowserSearchResults [] resultMors = result.getHostDatastoreBrowserSearchResults(); System.out.println("Browsing [esx_local_storage]..."); for (HostDatastoreBrowserSearchResults results : resultMors) { System.out.println("folder path: " + results.getFolderPath()); } ...
The folder structure in that specific datastore is like this
[esx_local_storage] |-test_root_folder |- test_folder |-empty_subfolder |- empty_folder
And when I run the code this is the result
: Browsing [esx_local_storage] ... : folder path: [esx_local_storage] : folder path: [esx_local_storage] test_root_folder : folder path: [esx_local_storage] test_root_folder/test_folder
So to me this looks like this is just ignoring the empty folders, this kind of make sense (to me), but the question is how do I get my empty folders :S
OK if found the Answer (sort of)
I noticed that if I use ...
... FileQueryFlags fqf = new FileQueryFlags(); fqf.setFileType(true); hdbss.setDetails(fqf); ...
... it will send back the empty folders... the problem is this is working for API version 2.5 but for 4.0 All I'm getting is InvalidRequest exception , any ideas?