Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xbmcgui # include xbmc gui module for script to use
- import xbmc # include xbmc module built in commands for script to use
- import os # include os module for file modification
- import shutil # include shutil module for removal of files and folders
- TARGETFOLDER = xbmc.translatePath( # defines TARGETFOLDER with X-platform directory structure
- 'special://home/userdata/addon_data/01' # the actual directory location of folder 01
- ) # Close the definition of TARGETFOLDER
- YESNOWINDOW = xbmcgui.Dialog().yesno( # Define YESWINDOW as kodi builtin window called Dialog().yesno
- "This Will Delete a folder", # Heading of builtin window
- "Click yes to delete", # body Text line 1
- "Click No to exit") # body text line 2
- if YESNOWINDOW: # Dialog window is activated with yesbutton
- _MSG = None # defines _MSG as blank, do not create a message. _MSG is what will links Notifications later on
- if os.path.exists(TARGETFOLDER): # if TARGETFOLDER exists at the defined location from above (line 6)
- try: # first attempt to....
- shutil.rmtree(TARGETFOLDER, ignore_errors=False)#remove TARGETFOLDER
- xbmc.executebuiltin("Notification(Folder has been deleted, All done,()")# if folder is removed, show notification (if yes button and folder is present)
- xbmc.executebuiltin("ActivateWindow(10000,return)")# then return to homescreen
- except OSError as rmerr: # if removal fails because file is not accessable
- _MSG = ("Error with delete dir: {}".format(rmerr)) # this will be the message output defined as rmerr
- except Exception as err: # if removal fails because kodi doesnt understand any or some of the code
- _MSG = ("Error with XBMC call: {}".format(err))# this will be the error message defined as err
- else: # if try is not selected and neither of the excepts line 22 and 24 are triggered
- _MSG = ("Folder {}, does not appear to be a directory"# this is the notification _MSG inside curly brackets will be printed
- .format(TARGETFOLDER)) # TARGETFOLDER path as defined by .format
- if _MSG: # if OSError-rmerr- or EXCEPTION-err- is activated due to a problem, ......read below
- xbmc.executebuiltin("Notification({},()".format(_MSG)) # pop up the notification window, inside curly brackets text will be from _MSG either OSError or Exception
- xbmc.executebuiltin("ActivateWindow(10000,return)") # then activate 10000,return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement