reduce123456789

import os
path = './hand'
filelist = os.listdir(path)
total_num = len(filelist)
print(filelist,',',total_num)
os.path.abspath(path)

i = 1  
for item in filelist:
    if item.endswith('.jpg'):
        src = os.path.join(os.path.abspath(path), item)
        # import pdb
        # pdb.set_trace() 
        if os.path.basename(src).split('_')[1][-1] in ['1','2','3','4','5','6','7','8','9']:
            i += 1
            try:
                os.remove(src)
                print('now we delet the image : {}'.format(src))
            except:
                continue
        # dst = os.path.join(os.path.abspath(path), 'lt01' + format(str(i), '0>5s') + '.jpg')
        # try:
        #     os.rename(src, dst)
        #     print ('converting %s to %s ...' % (src, dst))
        #     i = i + 1
        # except:
        #     continue
print ('total %d jpgs however we delet %d jpgs' % (total_num, i))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章