当前位置:   article > 正文

用Python 根据文件名查找数据文件

python os库按文件名近似查找文件
  1. #-*- coding: UTF-8 -*-
  2. import os
  3. import shutil
  4. AllFiles=[]
  5. NameFiles=[]
  6. def findFie(filePath):
  7. pathDir = os.listdir(filePath)
  8. for allDir in pathDir:
  9. # print(allDir)
  10. AllFiles.append(allDir)
  11. #pass
  12. #filepath = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\71\\71sns'
  13. #copyfile = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\71mtp'
  14. filepath = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\72\\72sns'
  15. copyfile = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\72mtp'
  16. shutil.rmtree(copyfile)
  17. os.mkdir(copyfile)
  18. findFie(filepath)
  19. def readFile():
  20. readFile = open('./jobname')
  21. i = 0
  22. for eachLine in readFile:
  23. i= i + 1
  24. #print(eachLine)
  25. NameFiles.append(eachLine.replace('\n','')) # 去掉换行符
  26. readFile()
  27. #字符串比较
  28. def doTheCompare():
  29. for x in NameFiles:
  30. print(x)
  31. for y in AllFiles:
  32. if x == y :
  33. copyFrom = os.path.join(filepath,x)
  34. copyTo = os.path.join(copyfile,x)
  35. shutil.copyfile(copyFrom,copyTo)
  36. else:
  37. pass
  38. #print ("file not find under sns process,thanks .please check with wumi.")
  39. doTheCompare()

转载于:https://www.cnblogs.com/TendToBigData/p/10501209.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/319414
推荐阅读
相关标签
  

闽ICP备14008679号