FileManager.py 766 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import shutil
  3. class FileManager:
  4. def __init__(self):
  5. pass
  6. @staticmethod
  7. def create_directory(cache_path):
  8. if not os.path.exists(cache_path):
  9. os.makedirs(cache_path)
  10. @staticmethod
  11. def write_in_file(file_path, content):
  12. with open(file_path, "wb") as file_open:
  13. file_open.write(content)
  14. file_open.close()
  15. return not FileManager.file_is_empty(file_path)
  16. @staticmethod
  17. def wipe_cache(cache_path):
  18. shutil.rmtree(cache_path)
  19. @staticmethod
  20. def file_is_empty(file_path):
  21. return os.path.getsize(file_path) == 0
  22. @staticmethod
  23. def remove_file(file_path):
  24. if os.path.exists(file_path):
  25. return os.remove(file_path)