Python批量删除指定文件夹下的文件


    
    
  1. """
  2. Python批量删除指定文件夹下的指定文件名的文件
  3. """
  4. import os
  5. def file_name(file_dir):
  6. list = []
  7. for root, dirs, files in os.walk(file_dir):
  8. for file in files:
  9. list.append(file)
  10. return list
  11. list = file_name( r'D:\pycharmprojects\never_give_up\PDBbingdata\PL_2017\pdb_pocket')
  12. print(list)
  13. # for i in range(len(list)):
  14. # print(list[i])
  15. # print(len(list))
  16. for i in range(len(list)):
  17. print(list[i])
  18. if list[i][ 6] == 'r':
  19. os.remove( r'D:\pycharmprojects\never_give_up\PDBbingdata\PL_2017\pdb_pocket'+ '/' + list[i])
  20. else:
  21. continue

  
  
  1. """
  2. Python批量删除指定文件夹下的指定文件名的文件
  3. """
  4. import os
  5. def file_name(file_dir):
  6. list = []
  7. for root, dirs, files in os.walk(file_dir):
  8. for file in files:
  9. list.append(file)
  10. return list
  11. list = file_name( r'D:\pycharmprojects\never_give_up\PDBbingdata\PL_2017\pdb_pocket')
  12. print(list)
  13. # for i in range(len(list)):
  14. # print(list[i])
  15. # print(len(list))
  16. for i in range(len(list)):
  17. print(list[i])
  18. if list[i][ 6] == 'r':
  19. os.remove( r'D:\pycharmprojects\never_give_up\PDBbingdata\PL_2017\pdb_pocket'+ '/' + list[i])
  20. else:
  21. continue

猜你喜欢

转载自blog.csdn.net/weixin_43202256/article/details/83068136
今日推荐