If you want a large amount of crawl destination data, you want to delete all the folders that were acquired halfway because they get in the way. I have put together a function for ease of use.
windows10 Anaconda 3.6.1
shutil shutil is one of the python standard libraries. Advanced directory operations are possible. [Official Reference] https://docs.python.jp/3/library/shutil.html
delete_folder.py
import os
import shutil
#By default, delete folders with 3 or less elements in the execution folder
def delete_folder( directory_dir= os.getwsd() ,size=3):
folder_list = os.listdir(directory_dir)
folder_dir = [os.path.join(directory_dir,i) for i in folder_list if len(os.listdir(os.path.join(directory_dir,i))) <= size ]
for folder in folder_dir:
print(folder+'To remove')
shutil.rmtree(folder)
print('Done')
Recommended Posts