cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
If you’ve changed your email address, now's the perfect time to update it on your Dropbox account and we’re here to help! Learn more 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: 

Calculate folder size to identify empty/0 bytes folders using python API

Calculate folder size to identify empty/0 bytes folders using python API

_shintaku_
Explorer | Level 3

Am trying to implement an API automation process to identify empty/0 bytes folders so I can delete them, similar to what was asked here.

 

I can't find 'size' attribute for folders in my requests response, my code is:-

 

 

import requests
import json

url = "https://api.dropboxapi.com/2/files/list_folder"

headers = {
"Authorization": "Bearer <access-token>",
"Content-Type": "application/json"
}

data = {
"path": "/Cat Watching Test",
"recursive": True
}

r = requests.post(url, headers=headers, data=json.dumps(data))

 

 

 

How do I calculate the size of folders from the API?

 

Screenshot 2022-10-09 091339.png

 

2 Replies 2

Здравко
Legendary | Level 20

@_shintaku_ wrote:

...

I can't find 'size' attribute for folders in my requests response, my code is:-

...


Hi @_shintaku_,

You can't find 'size' attribute cosa there is NOT such. Only files eventually residing in particular folder have such attribute on enumeration. To calculate total size, you need to enumerate entire folder content recursively and sum all files size (I'm still not certain that you need it actually).

You task can get up much easier if you check only for available entries in particular folder. If there are no any entries (files or folders) the folder is... empty. Isn't it much easier (no recursion, no calculations, etc)? On the post you provide link to, Greg posted some additional helpful tips, able to help automation for such a process (changes detection). Is something left no clear there?

Hope this helps.

_shintaku_
Explorer | Level 3

Thanks.

Your suggestion on checking folder for entries was what I used.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    _shintaku_ Explorer | Level 3
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?