Skip to main content
Question

Deleting Box Folder using Box name

  • May 21, 2025
  • 2 replies
  • 25 views

Forum|alt.badge.img

Hi,

 

I want to delete the Box folder and what i have is Box Folder Name and i also have its parenet folder name.

 

How can i get the box id by its name?

 

 

Regards

PK

2 replies

Forum|alt.badge.img

 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.


Forum|alt.badge.img

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);
        }