0

I'm trying to delete the directory from MEDIA_ROOT with shutil. After I have processed the files in the MEDIA_ROOT, I just want to clean up the directory along with the files in it. But getting permission denied error while using shutil. The default user is myuser. Is there a way to set folder with delete permission. I even tried the following permission in settings.py.

FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
FILE_UPLOAD_PERMISSIONS = 0o644

file-permission

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
Krish V
  • 486
  • 1
  • 5
  • 19

1 Answers1

0

Manually you can simply run the following command

sudo rm -r <path_to_MEDIA_ROOT>

If you want to still go with shutil and not use sudo, then you have to ensure to have write permissions to MEDIA_ROOT directory and then use

shutil.rmtree(path_to_MEDIA_ROOT)

to delete the directory and all its contents.

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145