Simple Addon to delete a specified folder
#1
Good Evening Community,

I'm hoping to get some help here.

I would like to make a simple addon using the shutil module.

I have my addon.xml done (at least I think I do)
In my default.py I want it to delete a specified folder in Kodi

Code:
import xbmc, xbmcgui

shutil.rmtree( special://home/xxx/xxx)

will this work on all platforms??

Thankyou for any help and guidance in advance
Reply
#2
(2015-05-15, 00:40)myfototv Wrote: Good Evening Community,

I'm hoping to get some help here.

I would like to make a simple addon using the shutil module.

I have my addon.xml done (at least I think I do)
In my default.py I want it to delete a specified folder in Kodi

Code:
import xbmc, xbmcgui

shutil.rmtree( special://home/xxx/xxx)

will this work on all platforms??

Thankyou for any help and guidance in advance


I have written this out and run it, but I get Script Error.

Please help community, thanks
Reply
#3
I have also tried this

Code:
import xbmcvfs

def xbmcvfs.delete     (special://home/userdata/addon_data/testfolder)

I get script error every time. please help
Reply
#4
You should use xbmc.translatePath (http://mirrors.kodi.tv/docs/python-docs/...nslatePath) to translate the special:// path to something the os knows
Reply
#5
(2015-05-15, 02:36)enen92 Wrote: You should use xbmc.translatePath (http://mirrors.kodi.tv/docs/python-docs/...nslatePath) to translate the special:// path to something the os knows

Good morning enen92,

Excellent, Day off work tommorrow/today Smile so Ill give it a go when i wake up. Ill post back here with progress,

I know this Is kind of pathetic basic stuff, But I guess there is always a starting block for all of us. thanks for your
help.
Reply
#6
No problem. In your snippet you haven't import the shutil module. Always have a look at your log file to check what the script error is about.

The same way you import xbmc and xbmcgui (you don't need this one) you should import shutil
Reply
#7
Hi enen92,

After a good Nights Sleep It bloody works!! you legend! here's the code, although i expect you know what the code looks like.

Code:
import xbmc, shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/testfolder')

shutil.rmtree(TARGETFOLDER)

The next thing id like to do is to add yesnodialog on executing the addon, so the procedure would be:

launch addon
>"do you want to delete testfolder "

>yes -run above script
>no- ActivateWindow(10000,return)

So in my plugin.program.tester folder I would have:

addon.xml
default.py - I'd like this to be the yesnodialog window (if yes run delete.py)
delete.py- this is the shutil.rmtree code above
icon.png

Im also guessing that I need to import xbmc, xbmcgui, shutil

Can you send me in the right direction again please, thanks
Reply
#8
banging my head against the wall Sad

it cant be this difficult.
Reply
#9
(2015-05-15, 15:32)myfototv Wrote: banging my head against the wall Sad

it cant be this difficult.

Making Progress

Code:
import xbmcgui

CONFIRM = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

ahhhh Smile now I want to assign action to the yes and no

Help apreciated
Reply
#10
if CONFIRM:
Shutilstuff
else:
Theotherstuff
Reply
#11
cheers dude,

ill have a go in a bit, im off out for a while, ill give it a go later, good man, always cryptic haha lmao

Ill post back with progress Wink
Reply
#12
Hi again enen92, this is the code so far

Code:
import xbmcgui
import xbmc
import os
import shutil

CONFIRM = 'yes'
TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if CONFIRM: shutil.rmtree(TARGETFOLDER)
else: xbmc.executebuiltin('Dialog.Close(all, true)')


It works, But If I click no, it still deletes the folder, any ideas?.

Also after I have sorted this, I will Have to put a check in there somewhere, so if (Folder 01) does not exist

xbmcgui.Dialog().ok("Folder Has Already Been Deleted")

But Ill get to this after. First I need A tiny bit more help for this if else. Pleasee,

I'm Guessing That Im not Assigning CONFIRM correctly.

Thanks for the help.
Reply
#13
Exclamation 
(2015-05-15, 23:25)myfototv Wrote: Hi again enen92, this is the code so far

Code:
import xbmcgui
import xbmc
import os
import shutil

CONFIRM = 'yes'
TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if CONFIRM: shutil.rmtree(TARGETFOLDER)
else: xbmc.executebuiltin('Dialog.Close(all, true)')


It works, But If I click no, it still deletes the folder, any ideas?.

Also after I have sorted this, I will Have to put a check in there somewhere, so if (Folder 01) does not exist

xbmcgui.Dialog().ok("Folder Has Already Been Deleted")

But Ill get to this after. First I need A tiny bit more help for this if else. Pleasee,

I'm Guessing That Im not Assigning CONFIRM correctly.

Thanks for the help.

I have updated it a bit more the code goes like this
Code:
import xbmcgui
import xbmc
import os
import shutil

CONFIRM = 'true'
DENY ='false'
TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if CONFIRM: shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")
else: xbmc.executebuiltin("ActivateWindow(10000,return)")

But I still get the deleted folder if I click no

arghh
Reply
#14
(2015-05-16, 00:09)myfototv Wrote: I have updated it a bit more the code goes like this
Code:
import xbmcgui
import xbmc
import os
import shutil

CONFIRM = 'true'
DENY ='false'
TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if CONFIRM: shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")
else: xbmc.executebuiltin("ActivateWindow(10000,return)")

But I still get the deleted folder if I click no

arghh

The result from the dialog is being assigned to the variable dialog but you are checking CONFIRM.

Try this:
Code:
import xbmcgui
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if dialog:
    shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")
else:
    xbmc.executebuiltin("ActivateWindow(10000,return)")
Reply
#15
(2015-05-16, 00:15)curti Wrote:
(2015-05-16, 00:09)myfototv Wrote: I have updated it a bit more the code goes like this
Code:
import xbmcgui
import xbmc
import os
import shutil

CONFIRM = 'true'
DENY ='false'
TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if CONFIRM: shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")
else: xbmc.executebuiltin("ActivateWindow(10000,return)")

But I still get the deleted folder if I click no

arghh

The result from the dialog is being assigned to the variable dialog but you are checking CONFIRM.

Try this:
Code:
import xbmcgui
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

if dialog:
    shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")
else:
    xbmc.executebuiltin("ActivateWindow(10000,return)")

Thanks Curti, and Enen92, I have made some notes on the code to see if i'm understanding it right. I quite like the cryptic clues, gets the grey matter thinking about resolving the problem Smile

Code:
# Do I really need to import os?
import xbmcgui
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')

#Dialog is assigned the yesno window with the text
dialog = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")

#So if yes, that would execute dialog hence the if dialog, basically dialog means yes
if dialog:
    shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted)")

#if no or close is pressed, that is the same as saying no, bypassing dialog(which means yes) so it activates window 10000
else:
    xbmc.executebuiltin("ActivateWindow(10000,return)")

I just couldn't get my head around the fact that dialog was yes. I assumed that dialog was neutral and the yes and no buttons where the activators. Works Perfectly by the way. Thankyou

The next thing I need to do Is to stop the script error when Folder 01 does not exist with

xbmcgui.Dialog().ok("Folder Has Already Been Deleted") , can someone point me in the right direction to learn about checking
if destination is true do something if not do something else?

Im want to learn more and write my own code if I can be pointed in the right direction.

Thank you loads Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Simple Addon to delete a specified folder1