Kodi Community Forum

Full Version: Help with Python to delete cache (Autoexec.py)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I have a script that runs within Autoexec.py to delete the contents of the cache on every launch and it works great.

I am looking for some help because I would like to delete everything within the cache folder with the exception of kodi.log and kodi.log.old

The script I use is below, would anyone be able to help please.
Code:
#!/bin/sh

import os
import shutil

#Define TEMP as the path to special://home/temp
TEMP = xbmc.translatePath(
    'special://home/temp'
    )
                
#Delete the cache folder.
folder = TEMP
if os.path.exists(TEMP):
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path): shutil.rmtree(file_path)
            donevalue = '1'
        except Exception, e:
#            print e
Hello,

I just posted my solution for this on another thread.

Here is the link: My Post

I welcome feedback - I'm not a developer, but I like to learn.

Thanks!