I have a script that removes an entire directory, but I would like to amend it to delete everything with the exception of two files (kodi.log
and kodi.old.log
), so the extension .log
needs to be skipped.
The script I have is
TEMP = xbmc.translatePath(
'special://home/temp'
)
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
Any ideas would be greatly appreciated.