import os import os.path import shutil from utils.constants import * def clear_cache_folder(folder_path): try: # Check whether the folder exists if os.path.exists(folder_path): # Iterate through all contents in the folder for filename in os.listdir(folder_path): file_path = os.path.join(folder_path, filename) # Delete it if it is a file if os.path.isfile(file_path): os.remove(file_path) # Recursively delete it if it is a directory elif os.path.isdir(file_path): shutil.rmtree(file_path) print(f"Cache folder '{folder_path}' has been cleared.") else: print(f"Folder '{folder_path}' does not exist.") except Exception as e: import traceback traceback.print_exc() print(f"An error occurred while clearing the cache folder: {e}") def main(): clear_cache_folder(CACHE_DIR) # clear_cache_folder(HTML_CACHE_DIR) # clear_cache_folder(IMAGE_CACHE_DIR) # clear_cache_folder(EXCEL_CACHE_DIR) if __name__ == "__main__": main()