Posts: 78
Joined: Jul 2015
Reputation:
2
Hello I'm making a Addon... I wanna delete all files in kodi database folder.
(special://database) or sdcard/Android/data/org.xbmc.kodi/files/.kodi/userdata/Database/
How to do this? Which python codes? Can anyone help?
Posts: 7,650
Joined: Jun 2011
Reputation:
287
personally I get alarmed at the idea that addons out there want to delete DB files...
Posts: 131
Joined: Sep 2015
Does anyone know how I would delete the temp folder on initial run?
I am using the autoexec.py in userdata with the following
Code:
import os
import shutil
if os.path.exists(special://temp):
log("shutil.rmtree Removing path")
shutil.rmtree(special://temp, ignore_errors=true)
However nothing happens, the folder does not get deleted. Any ideas?[/code]
Posts: 131
Joined: Sep 2015
Code:
15:48:06 T:2472 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.SyntaxError'>
Error Contents: ('invalid syntax', ('C:\\Users\\Thomas\\AppData\\Roaming\\Kodi\\userdata\\autoexec.py', 11, 8, '\t\t\t\telif os.path.isdir(file_path): shutil.rmtree(file_path)\n'))
SyntaxError: ('invalid syntax', ('C:\\Users\\Thomas\\AppData\\Roaming\\Kodi\\userdata\\autoexec.py', 11, 8, '\t\t\t\telif os.path.isdir(file_path): shutil.rmtree(file_path)\n'))
-->End of Python script error report<--
Thanks for you help
Posts: 131
Joined: Sep 2015
2016-02-04, 18:12
(This post was last modified: 2016-02-04, 18:12 by User 289973.)
Thank you very much, it works flawlessly.
If i wanted to apply the same principle to the addons/packages folder would it be as simple as just copying the same cope again below but changing it to this?
Code:
TARGETFOLDER = xbmc.translatePath(
'special://home/temp'
)
path = TARGETFOLDER
folder = TARGETFOLDER
if os.path.exists(TARGETFOLDER):
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
TARGETFOLDER = xbmc.translatePath(
'special://addons/packages'
)
path = TARGETFOLDER
folder = TARGETFOLDER
if os.path.exists(TARGETFOLDER):
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
Posts: 131
Joined: Sep 2015
Just a quick one guys.
The above script is fantastic but it disables me being able to use a log.
So how easy would it be to use the same principle above but instead of deleting the entire temp folder just deleting the .fi files within the folder?
Sort of a delete *.fi script instead of the entire folder.
Thanks in advance guys
Posts: 131
Joined: Sep 2015
Nevermind, managed to do it.
For anyone thats interested the code is as follows
Code:
scandirs = xbmc.translatePath(
'special://home/temp'
)
path = scandirs
exts = ('.fi')
if os.path.exists(scandirs):
for root, dirs, files in os.walk(path):
for currentFile in files:
if any(currentFile.lower().endswith(ext) for ext in exts):
os.remove(os.path.join(root, currentFile))