Getting all files in a folder (with recursion) via Box CLI
CompletedI am looking for confirmation on what I think I'm seeing in the Box CLI "search" command.
If I use
box search --type=file ...other parameters
I cannot use a wild card or "blank" search term. however if I use:
box search -- type=file ...other parameters... --mdfilter="valid metadatafilter"
I can use a "blank" search term and get results, however it seems to be limited to 100. This is not mentioned in the documentation
https://github.com/box/boxcli/blob/main/docs/search.md
And I have not figured out how to "step" to the next set of 100 results.
Both paths leave something to be desired, but for now I'd just like to know if there's a way to get the "next 100" or a way to get all.
Honestly all I want is a count of the files in a folder and it's children. It'd be great if we didn't have resort to these tricks to accomplish something that's available in the UI.
-
Official comment
Hey John!
When you say you are getting results, are you running a command like this:
box search "blank" --type=file --ancestor-folder-ids=<folder_id> --mdfilter=enterprise.<template_key>.<field>=<value>
To see the next group of results, I would refer to our pagination documentation here.
In general, I would not recommend using the search APIs to recursively go through a folder's content. I don't know your full use case, but I would probably write a powershell script that contains some recursive logic using the get folder items endpoint.
Alex, Box Developer Advocate
Comment actions -
Alex,
Thanks for the response. I abandoned the recursive search technique because it took a long time to get what I was after. Unfortunately I'm not seeing a way within the Box API interface to accomplish what I was after.
The recursion was being controlled via the powershell script and even using the get Folder items it was pretty intensive.
My goal was simply to list the total # of files in a folder including subfolders. Sadly for the level of accuracy that I need, just opening up the page in the Box web app gives me the information much more quickly.Ideally I'd be able to get these files and provide our user base the count of files by type (i.e. photos, drawings, pdfs etc)
Thanks again for responding, and if you can promote a recursive api endpoint that could help.
-
Ah. I appreciate you letting me know. You might check our Pulse site for this. If it exists, upvote it. The product team watches that site for what to put on the roadmap.
-
Thanks, I voted up this idea that I think relates.
Please sign in to leave a comment.
Comments
4 comments