2016-03-19, 02:23
I'm trying to figure out a way to delete all subfolders and files within userdata except a certain folder. I found this code but I'm not sure how to add an exception to it. Anyone have an idea?
Code:
TARGET = xbmc.translatePath(
'special://home/userdata'
)
path = TARGET
folder = TARGET
if os.path.exists(TARGET):
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