File size: 1,171 Bytes
b6beed8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 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() |