[关闭]
@Scrazy 2016-11-29T12:24:50.000000Z 字数 507 阅读 809

扫面目标文件夹下的指定类型文件

python


  1. import os
  2. from collections import deque
  3. def search_file(file_format, path=None):
  4. if path is None:
  5. path = os.getcwd() # 默认为自家目录
  6. Q = deque(os.listdir(path))
  7. while Q:
  8. u = Q.popleft()
  9. child_path = os.path.join(path, u)
  10. if not os.path.isdir(child_path):
  11. file = os.path.split(child_path)[1]
  12. suffix = file.split('.')[1]
  13. if suffix == file_format:
  14. print(file)
  15. if __name__ == '__main__':
  16. path = input('Please input the path {} >'.format('\n'))
  17. if path == '':
  18. path = None
  19. file_format = input('Please input the file type {} >'.format('\n'))
  20. search_file(file_format, path)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注