Skip to main content
Question

List all files inside box folder

  • May 21, 2025
  • 2 replies
  • 20 views

Forum|alt.badge.img

Hi,

 

I want to list files inside box folder,we are using box java api for this.

 

Can anyone help me to achieve this.I know how to list folders inside box folder, but i need help on listing files.

 

BoxFolder folder = new BoxFolder(api, boxFolderId);

for (BoxItem.Info itemInfo : folder) {

Something need to be done here.

 

}

 

Regards

Prasoon

2 replies

Forum|alt.badge.img

 The sample code you provided should return the items in a folder, which will include both folders and files.

 

The example below from our Java SDK documentation shows how get all folder items, and then check if each item returned is a file or folder. 

 

BoxFolder folder = new BoxFolder(api, "id");
for (BoxItem.Info itemInfo : folder) {
    if (itemInfo instanceof BoxFile.Info) {
        BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
        // Do something with the file.
    } else if (itemInfo instanceof BoxFolder.Info) {
        BoxFolder.Info folderInfo = (BoxFolder.Info) itemInfo;
        // Do something with the folder.
    }
}

Forum|alt.badge.img

Is this this only method to get the meta data (name, size, etc) of all the files in a folder?

I ask because I am using it to traverse a few directories and it is VERY slow.

Is there perhaps a single "ls" (unix cmd)  equivalent that is faster than having to enumerate each FileInfo?