0

I have a Directory called "master" inside I have sub directories as so.

|master----
         |test.directory.one
         |test directory.two
         |test.directory.three
         |test.directory.four
         |test.directory.five
         |this.directory.keep

I would like to create a python script that deletes

all the directories that start with test.directory and ignore anything else

Thanks for you help. Any guidance is greatly appreciated.

Simontfs

Simon Jeal
  • 153
  • 2
  • 4
  • 14

2 Answers2

2
import glob
import shutil

deldirs = glob.glob("path/to/master/test.directory.*")
for dir_ in deldirs:
    shutil.rmtree(dir_)
Adam Smith
  • 52,157
  • 12
  • 73
  • 112
0

Thanks Adam Smith,

It was almost what I was looking for here is the edited code.

import glob
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/addons/')

addonvideo = glob.glob(xbmc.translatePath('special://home/addons/plugin.video.*'))
for dirname in addonvideo:
    shutil.rmtree(dirname)

Im creating some maintenance scripts for Kodi, I'm new to python but slowly getting my head around it, with the help of you guys. Thanks a million!

I am going to elaborate on this code and would like to post back if I need some more guidance if poss. Cheers :)

Simon Jeal
  • 153
  • 2
  • 4
  • 14