shutil.rmtree, os.path, delete sub-folders, format

#====
#This script will check how many files in sub-folders.
#Will delete the sub-folders if the files are not enough.
#====

import os
import shutil
from os import walk
import os.path

#mypath='./'
mypath='/home/xxx/awk/'

num = 6
count_at_least = 0

for (dirpath, dirnames, filenames) in walk(mypath):

   for dir in dirnames:

       for (dirpath1, dirnames1, filenames1) in walk(mypath+dir):
          if len(filenames1) < num:
              count_at_least = count_at_least + 1
              print(dirpath1)
            # shutil.rmtree(dirpath1)

print('Less than {} images per class is {}. Will delete.'.format(num,count_at_least) )


#http://blog.csdn.net/duhai/article/details/22404627
#http://www.jb51.net/article/57293.htm
#https://www.cnblogs.com/dwtt/p/7772639.html

 

posted on 2018-01-23 14:19  cdekelon  阅读(141)  评论(0编辑  收藏  举报

导航