2016-03-27, 08:02
This code works like a dream! I'm very new to python and am stumbling through to understand and learn as I go. How can i modify that code so i can input a list of folders to remove instead of copying the code each time? Also, is there a way i can remove the contents of a folder while leaving select files and folders alone?
Would it be something like this?:
TARGETFOLDER = xbmc.translatePath(
'special://home/userdata/addon_data/folder1,
special://home/userdata/addon_data/folder2
special://home/userdata/addon_data/folder3'
)
path = TARGETFOLDER
folder = TARGETFOLDER
if os.path.exists(TARGETFOLDER):
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
Thank you very much in advance!
Would it be something like this?:
TARGETFOLDER = xbmc.translatePath(
'special://home/userdata/addon_data/folder1,
special://home/userdata/addon_data/folder2
special://home/userdata/addon_data/folder3'
)
path = TARGETFOLDER
folder = TARGETFOLDER
if os.path.exists(TARGETFOLDER):
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
Thank you very much in advance!