jianting.py 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import glob
  3. def search_file(file_path, file):
  4. # file_path指定路径, file指定文件名
  5. path = file_path
  6. file_list = []
  7. for root, dirs, files in os.walk(path):
  8. file_pattern = os.path.join(root, file)
  9. for f in glob.glob(file_pattern):
  10. file_list.append(f)
  11. return file_list
  12. def into(f):
  13. pass
  14. # with open(f, 'wb') as i:
  15. # pass
  16. # f = str.encode(f)
  17. # i.write(f)
  18. def func(file_list):
  19. if not file_list:
  20. print("没有这个文件")
  21. else:
  22. print("一共找出 %d 个文件" % len(file_list))
  23. print("找出的文件如下: ")
  24. for f in file_list:
  25. print(f)
  26. into(f)
  27. # with open(f, 'wb') as i:
  28. # f = str.encode(f)
  29. # i.write(f)
  30. print('查找文件结束')
  31. if __name__ == '__main__':
  32. file_path = r'C:\Users\admin\Desktop\newscore'
  33. file = 'id_json.txt'
  34. file_list = search_file(file_path, file)
  35. func(file_list)