Delete files using autoexec.py kodi startup
#1
Hi, i'm running osmc on pizero,
i can manually delete files in my osmc .kodi folder by using ssh at command line:
rm .kodi/temp/*.fi

I want to automate this at startup and have added an autoexec.py file to my .kodi/userdata folder

import os
myfile="/.kodi/temp/*.fi"

## if file exists, delete it ##
if os.path.isfile(myfile):
os.remove(myfile)
else: ## Show an error ##
print("Error: %s file not found" % myfile)
On reboot the files are not deleted

Could someone help ?
Reply
#2
I just got this working for me as code for autoexec.py.
It works in Android and Windows.

Code:
import os, shutil, xbmc

path = xbmc.translatePath('special://temp')

if os.path.exists(path):
    for f in os.listdir(path):
        fpath = os.path.join(path, f)
        try:
            if os.path.isfile(fpath):
                if not fpath.lower().endswith('.log'):
                    os.unlink(fpath)
            elif os.path.isdir(fpath):
                shutil.rmtree(fpath)
        except Exception as e:
            print e
else:
    print path

path = xbmc.translatePath('special://home/addons/packages')

if os.path.exists(path):
    for f in os.listdir(path):
        fpath = os.path.join(path, f)
        try:
            if os.path.isfile(fpath):
                os.unlink(fpath)
        except Exception as e:
            print e
else:
    print path
Reply

Logout Mark Read Team Forum Stats Members Help
Delete files using autoexec.py kodi startup0