cleaner.py 450 B

123456789101112131415
  1. import os
  2. import shutil
  3. def clean(results):
  4. '''
  5. Cleans the given directory of all files and folders
  6. '''
  7. results_dir = os.path.dirname(results.directory)
  8. if os.path.exists(results_dir):
  9. for file in os.listdir(results_dir):
  10. if not os.path.exists(os.path.dirname(file)):
  11. shutil.rmtree(os.path.join(results_dir, file))
  12. else:
  13. os.remove(os.path.join(results_dir, file))