folder deleter ignores some safe folders
This commit is contained in:
parent
8ac831f6c9
commit
d3e4c6332c
1 changed files with 5 additions and 4 deletions
|
|
@ -241,10 +241,11 @@ async def folder_setup():
|
||||||
for folder_name in folder_names:
|
for folder_name in folder_names:
|
||||||
if not os.path.exists(folder_name):
|
if not os.path.exists(folder_name):
|
||||||
os.mkdir(folder_name)
|
os.mkdir(folder_name)
|
||||||
|
return folder_names
|
||||||
|
|
||||||
async def delete_all_files(path):
|
async def delete_all_files(path, safe_folders):
|
||||||
for filename in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
if os.path.isdir(path+filename):
|
if os.path.isdir(path+filename) and not path+filename in safe_folders:
|
||||||
shutil.rmtree(path+filename)
|
shutil.rmtree(path+filename)
|
||||||
elif os.path.isfile(path+filename):
|
elif os.path.isfile(path+filename):
|
||||||
os.remove(path+filename)
|
os.remove(path+filename)
|
||||||
|
|
@ -334,8 +335,8 @@ async def on_ready():
|
||||||
|
|
||||||
print('We have logged in as {0.user}'.format(bot))
|
print('We have logged in as {0.user}'.format(bot))
|
||||||
#stuff to do if first run
|
#stuff to do if first run
|
||||||
await folder_setup()
|
folders_made = await folder_setup()
|
||||||
await delete_all_files("tmp/")
|
await delete_all_files("tmp/", folders_made)
|
||||||
task_loop.start()
|
task_loop.start()
|
||||||
|
|
||||||
@bot.command(
|
@bot.command(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue