Python supprimer le répertoire non vide
import shutil
shutil.rmtree('/folder_name')
Energetic Emu
import shutil
shutil.rmtree('/folder_name')
import shutil
shutil.rmtree('/folder_name')
shutil.rmtree('/folder_name', ignore_errors=True) # for read only files
'''
Check if a Directory is empty : Method 1
'''
if len(os.listdir('/home/varun/temp') ) == 0:
print("Directory is empty")
else:
print("Directory is not empty")
# Delete everything reachable from the directory named in 'top',
# assuming there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could delete all your disk files.
import os
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))