Skip to content

Instantly share code, notes, and snippets.

@lucasrcezimbra
Created March 27, 2021 19:50
Show Gist options
  • Save lucasrcezimbra/856befcf800b7493084871e08c8bd70f to your computer and use it in GitHub Desktop.
Save lucasrcezimbra/856befcf800b7493084871e08c8bd70f to your computer and use it in GitHub Desktop.
Recursive delete files from S3 via Django Storages
from django.core.files.storage import default_storage
def recursive_delete(fullpath):
dirs, files = default_storage.listdir(fullpath)
for file in files:
filepath = f'{fullpath}{file}'
print(f'deleting {filepath}')
default_storage.delete(filepath)
for dir in dirs:
new_dir = f'{fullpath}{dir}/'
print(f'going to new dir {new_dir}')
recursive_delete(new_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment