Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

lyza3's avatar
lyza3
Explorer | Level 4
5 years ago
Solved

How to delete all files in a folder by API

Hi API Team,

I am using dropbox folders temporarily to upload videos to youtube. I need to clean/delete files from Dropbox files after I upload them to youtube since I don't need them anymore and to free up space in Dropbox.

1. Do you have a setting where we can set time to delete files? ex: every day, every Monday at 23:59
2. Do you have a cron job/automation/bot/software that will clean folders for example at 23:59 every day?

 

 I am able to delete individual files and folders as follows (API Doc):

curl -X POST https://api.dropboxapi.com/2/files/permanently_delete \
    --header "Authorization: Bearer " \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math/Prime_Numbers.txt\"}"

 How to delete all files in a folder with out deleting the folder? Something like *.* for all files:

{
    "path": "/uploads/*.*"
}

 I could not interpret the path pattern - path String(pattern="(/(.|[\r\n])*)|(ns:[0-9]+(/.*)?)|(id:.*)")

Can you please guide me to delete all files in a folder ?

Thanks!

  • The Dropbox API does not offer a way to configure automatic deletions like this, nor does it offer a way to specify a wildcard like that or otherwise just delete everything in a particular folder without deleting the folder itself, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

     

    Instead, you'd need to specify each item you do want to delete. Also, /2/files/permanently_delete is for permanently deleting; you can use /2/files/delete_v2 to just delete things. (Deleted items are automatically permanently deleted after a certain amount of time. You can find more information in the help center.) Also, you can use /2/files/delete_batch to delete multiple items at once (though you still need to specify each one).

6 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

    The Dropbox API does not offer a way to configure automatic deletions like this, nor does it offer a way to specify a wildcard like that or otherwise just delete everything in a particular folder without deleting the folder itself, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

     

    Instead, you'd need to specify each item you do want to delete. Also, /2/files/permanently_delete is for permanently deleting; you can use /2/files/delete_v2 to just delete things. (Deleted items are automatically permanently deleted after a certain amount of time. You can find more information in the help center.) Also, you can use /2/files/delete_batch to delete multiple items at once (though you still need to specify each one).

  • Kirill-TpuSoft's avatar
    Kirill-TpuSoft
    Helpful | Level 5
    2 years ago

    Hi Greg

    I tried to call api https://api.dropboxapi.com/2/files/permanently_delete
    but received the following message:
    Error in call to API function "files/permanently_delete": Your app is not permitted to access this endpoint because it does not have the required scope 'files.permanent_delete'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.

    In the App settings of permissions this scope (files.permanent_delete) is avalaible only for Team, but the api https://api.dropboxapi.com/2/files/permanently_delete - is user endpoint. I can't enable files.permanent_delete  for the individual scopes. I can't find any way to use this api function. Thanks
  • iNeil's avatar
    iNeil
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

    Kirill-TpuSoft 

    That’s correct, the /2/files/permanently_delete endpoint is only available for team-linked apps. The permanent delete API functionality is unavailable for individual user-linked apps.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    2 years ago

    iNeil, In general permanent deletion is available for all users (including personal). Why does API behave different at all? 🤔 Isn't it some sort of oversight?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

    We don't have information to share on the decisions behind the design of any particular endpoint/scope on the API, but this is the expected behavior for this endpoint and scope.

  • Kirill-TpuSoft's avatar
    Kirill-TpuSoft
    Helpful | Level 5
    2 years ago

    Thanks a lot for fast support, got it 
    Im Sorry,  I inadvertently didn't notice that the documentation included the following text: “Note: This endpoint is only available for Dropbox Business apps.”

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If 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, Facebook or Instagram.

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!