def delete_recursive(path, dirs): ''' Delete files and dirs recursively. ''' for directory in dirs: dirs2, files = xbmcvfs.listdir(os.path.join(path, directory)) for file in files: xbmcvfs.delete(os.path.join(path, directory, file)) delete_recursive(os.path.join(path, directory), dirs2) xbmcvfs.rmdir(os.path.join(path, directory))
def delete_node_by_id(self, view_id): ''' Remove node and children files based on view_id. ''' path = xbmc.translatePath("special://profile/library/video/") dirs, files = xbmcvfs.listdir(path) for directory in dirs: if directory.startswith('jellyfin') and directory.endswith( view_id): _, files = xbmcvfs.listdir(os.path.join(path, directory)) for file in files: self.delete_node(os.path.join(path, directory, file)) xbmcvfs.rmdir(os.path.join(path, directory))
def delete_nodes(self): ''' Remove node and children files. ''' path = xbmc.translatePath("special://profile/library/video/") dirs, files = xbmcvfs.listdir(path) for file in files: if file.startswith('jellyfin'): self.delete_node(os.path.join(path, file)) for directory in dirs: if directory.startswith('jellyfin'): _, files = xbmcvfs.listdir(os.path.join(path, directory)) for file in files: self.delete_node(os.path.join(path, directory, file)) xbmcvfs.rmdir(os.path.join(path, directory))
from kodi_six import xbmc, xbmcgui, xbmcvfs import os WIN = xbmcgui.Window(10000) if not WIN.getProperty('iagl.script_started'): WIN.setProperty('iagl.script_started', 'True') try: xbmc.log(msg='IAGL: Clear cache script started', level=xbmc.LOGDEBUG) import shutil from resources.lib.main import iagl_utils IAGL = iagl_utils() #IAGL utils Class success = list() try: if not xbmcvfs.rmdir(os.path.join(IAGL.get_temp_cache_path(), '')): shutil.rmtree(IAGL.get_temp_cache_path(), ignore_errors=True) xbmc.log(msg='IAGL: Cache directory was cleared with shutil', level=xbmc.LOGDEBUG) else: xbmc.log(msg='IAGL: Cache directory was cleared', level=xbmc.LOGDEBUG) IAGL.get_temp_cache_path() #Remake folder success.append(True) except Exception as exc1: success.append(False) xbmc.log( msg= 'IAGL Error: Cache directory could not be cleared, Exception %(exc)s' % {'exc': str(exc1)}, level=xbmc.LOGERROR) try: IAGL.delete_all_list_cache()