You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
BobHabig
7 years agoHelpful | Level 5
reconstitute file tree structure from list_folder recursive response
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.
- Greg-DBDropbox StaffAs 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!- BobHabigHelpful | 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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,910 PostsLatest Activity: 3 days agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!