Hi @ujjwalkarjee
There is no API endpoint to give you this information directly.
You can, however, create a method to recursively get this information.
Be aware that this will use one request per folder, and it will only work if the folder has less than 1000 items between files, folders or web-links.
If you expect that folders have more than 1000 items, then you need to modify the logic to get the next page, until you reach the end. Might be more explicit if you use the get_items
.
This example is in Python, but I’m confident you’ll get the idea:
from typing import List
from boxsdk import JWTAuth, Client
from boxsdk.object.folder import Folder
def get_client() -> Client:
config = JWTAuth.from_settings_file("config.json")
return Client(config)
def get_folder_by_id(client: Client, folder_id: str) -> Folder:
return client.folder(folder_id=folder_id).get()
def get_total_files_in_folder(client: Client, folder_id: str, depth: int = 0) -> int:
folder = get_folder_by_id(client, folder_id)
if not hasattr(folder, "item_collection"):
return 0
entries = folder.item_collection.get("entries")
total_files = 0
for entry in entries:
if entry.type == "file":
total_files += 1
if entry.type == "folder":
total_files += get_total_files_in_folder(client, entry.id, depth + 1)
print(" " * depth + "Folder: " + folder.name + " total : " + str(total_files))
return total_files
def main():
client = get_client()
total_files = get_total_files_in_folder(client, "0")
print("Total Files: " + str(total_files))
if __name__ == "__main__":
main()
This results in:
Folder: 100k total : 0
Folder: aaaa total : 0
Folder: Cenotes total : 0
Folder: Eagle Ray Bay total : 0
Folder: Barbosa total : 1
Folder: 2023-08-17 total : 1
Folder: Ras Mohamed total : 1
Folder: Sharks Bay total : 0
Folder: Thistlegorm total : 0
Folder: Tropicana total : 0
Folder: Bookings total : 7
Folder: Test total : 0
Folder: test total : 0
Folder: Uploads total : 9
Folder: Box UI Elements Demo total : 12
Folder: Classification Service Demo total : 1
Folder: JWT Folder for UI Sample Apps total : 1
Folder: Box-Dive-Waiver.pdf 2023-08-16 08.49.44 total : 2
Folder: Box-Dive-Waiver.pdf 2023-08-16 09.08.09 total : 2
Folder: My Signed Documents total : 4
Folder: Shared with RB total : 1
Folder: Waivers total : 4
Folder: Webhook total : 0
Folder: All Files total : 30
Total Files: 30
Hope this helps.
Cheers