Welcome to the new Box Support website. Check out all the details here on what’s changed.

Deleting Box Folder using Box name

New post

Comments

2 comments

  • Murtza

     You can search for a folder by name using the Search endpoint. You can limit the search results to just folders by setting the type parameter to folder. 

     

    Once you have the folder id, you can use the Delete Folder endpoint.

    0
    Comment actions Permalink
  • kendomen

    Using 's example, I tested this out and it seems to work...

     

            BoxSearchParameters boxSearchParameters = new BoxSearchParameters("ken");  // search by name
            boxSearchParameters.setType("folder");                                     // only return folders
    
            BoxSearch boxSearch = new BoxSearch(userAPI);
    
            List parentFolderId = new ArrayList<>();
            parentFolderId.add("0"); 
            boxSearchParameters.setAncestorFolderIds(parentFolderId);
    
            PartialCollection results = boxSearch.searchRange(0, 10, boxSearchParameters);
            for (Iterator iterator = results.iterator(); iterator.hasNext(); ) {
                BoxItem.Info info = iterator.next();
                System.out.println(info.getName() + " [" + info.getID() + "]");
                BoxFolder boxFolder = (BoxFolder)info.getResource();
                boxFolder.delete(true);
            }
    0
    Comment actions Permalink

Please sign in to leave a comment.