cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

reconstitute file tree structure from list_folder recursive response

reconstitute file tree structure from list_folder recursive response

BobHabig
Helpful | Level 5

Hi,

 

I am using the list_folder endpoint with the recursive arg. I am looking for a way (in javascript) to take the results and create an object that is organized into the nested file tree structure one would see while interacting with Dropbox. I am not from a CS background and may be unaware of a good algorithm for this, but regardless, I would love some help if anyone could lend a hand.

 

here is an example of the recursive response (paths only): 

/l_one

/l_one/common

/l_one/common/2016

/l_one/common/2017

/l_one/common/2018

/l_one/common/2016/folder_one

/l_one/common/2016/folder_two

/l_one/common/2016/folder_three

/l_one/common/2016/folder_four

/l_one/common/2016/folder_five

/l_one/common/2017/folder_one

/l_one/common/2017/folder_two

/l_one/common/2017/folder_three

/l_one/common/2017/folder_four

/l_one/common/2017/folder_five

/l_one/common/2018/folder_one

/l_one/common/2018/folder_two

/l_one/common/2018/folder_three

/l_one/common/2018/folder_four

/l_one/common/2018/folder_five

/l_one/common/2016/folder_one/file_one.pdf

/l_one/common/2016/folder_one/file_two.pdf

/l_one/common/2016/folder_one/file_three.pdf

/l_one/common/2016/folder_two/file_one.pdf

/l_one/common/2016/folder_two/file_two.pdf

/l_one/common/2016/folder_two/file_three.pdf

/l_one/common/2016/folder_three/file_one.pdf

/l_one/common/2016/folder_four/file_one.pdf

/l_one/common/2016/folder_four/file_two.pdf

 

same idea for pdf's in 2017 and 2018

 

of course what i want is  nested JS object:

fileTree = {
  l_one: {
    common: {
      2016: {

        folder_one: [*pdf's here*],

        folder_two: [*pdf's here*],
        ...
        ...
      },
      2017: {...},
      2018: {...}
    }   

  }

any help is greatly appreciated!

* I am not necessarily looking for Dropbox api endpoint tips - if there is a better way to use list_folder, I am interested, but I am mostly looking for a javascript specific way of building this object.

2 Replies 2

Greg-DB
Dropbox Staff
As you mentioned, this is probably more of a question about handling data in JavaScript then about the Dropbox API itself. (It sounds like you have a good idea of how to use list_folder already. Make sure you do check has_more and call back to list_folder_continue if/as necessary though.)

I don't believe we have any sample code for building the tree like this unfortunately, but hopefully some other developer on the forum here has something they can share!

BobHabig
Helpful | Level 5

I do think we missed the opportunity to take advantage of the has_more / continue feature of the API. My current deadline for a demo is too close to try that, but that is likely the best overall way. With that, I can build the Object I'm looking for step by step instead of having this challenge in front of me. Thanks for the tip, and yes - hope someone else has some insight for how to go about this. 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    BobHabig Helpful | Level 5
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?