Recursively remove links under a specified folder path

Discussion created by Michael_Lowry on Jan 28, 2016
Latest reply on Apr 3, 2017 by Wolfgang_Brueckler_1288
I want to set up a process to remove all links benath a specified folder. The only way to delete a link using the Java Application Interface is using the DeleteLink class, and the only way to construct an object of this class is based on a FolderListItem object. Ultimately the only way I have found to delete links is something like this:

  1. Begin with aFolderTreeobject.
  2. Create anIFolderobject based on a the specific folder path, using FolderTree.getFolder(String linkPath).
  3. Create aFolderListusing the IFolder.
  4. Create an iterator over objects/links in that path, usingFolderList.iterator().</li>
  5. For each entry, use FolderListItem.isLink() to determine whether the item is a link.
  6. If so, construct aDeleteLinkobject from the FolderlistItem, and send the request to the Automation Engine.

  7. This will delete the links directly under just the specified directory, but will not delete links from subdirectories. To delete links under sub-directories, one would have to return to the IFolder, and use the subfolder() method to proceed to subfolders, in a recursive way.

    I thought it might be possible to use SearchObject to list only the links under a specified folder path, but there does not appear to be a way to do this. One can list all objects including links, and then parse them one at a time, checking whether a particular search result is a link. But the one still has the challenge of converting a SearchResultItem to something that can be used with DeleteLink. Perhaps this could be done using the internal use only FolderListItem constructor, but I have not tried this.

    Is there a better way to recursively remove links under a specified folder path?