1import os
2import glob
3
4files = glob.glob('/YOUR/PATH/*')
5for f in files:
6 os.remove(f)
7
1import os, shutil
2folder = '/path/to/folder'
3for filename in os.listdir(folder):
4 file_path = os.path.join(folder, filename)
5 try:
6 if os.path.isfile(file_path) or os.path.islink(file_path):
7 os.unlink(file_path)
8 elif os.path.isdir(file_path):
9 shutil.rmtree(file_path)
10 except Exception as e:
11 print('Failed to delete %s. Reason: %s' % (file_path, e))
12
1import shutil
2
3dir_path = '/tmp/img'
4
5try:
6 shutil.rmtree(dir_path)
7except OSError as e:
8 print("Error: %s : %s" % (dir_path, e.strerror))
9