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

A faster way to list files in a folder?

New post

Comments

2 comments

  • pcapdown

    By the way, when I say slow, I mean it takes almost 1 second to get each ItemInfo:

    for (BoxItem.Info itemInfo : targetFolder) {
    if (itemInfo instanceof BoxFolder.Info) {
    ...
    etc.

     

    0
    Comment actions Permalink
  • billevans1963

    Ok, I finally figured out why it is so slow:  By default, the method gets only one Box.FileInfo object at a time from the server.  To speed up you need to use pagination with max limit of 100.  Something like the following:

     


    int offset = 0; //Start
    int pageSize = 100;
    while (true) {
       Collection itemsInFolder = targetFolder.getChildrenRange(offset, pageSize, "name", "size");
       for (BoxItem.Info itemInfo : itemsInFolder) {
           if (itemInfo instanceof BoxFile.Info) {
                 ....
            }
            else if (itemInfo instanceof BoxFolder.Info) {

                ...
            }
        }
        if (itemsInFolder.size() < pageSize) break;           //Less than max returned signals end
        offset += pageSize;
    }

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.