Created
March 27, 2021 19:50
-
-
Save lucasrcezimbra/856befcf800b7493084871e08c8bd70f to your computer and use it in GitHub Desktop.
Recursive delete files from S3 via Django Storages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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