网站建设资讯

NEWS

网站建设资讯

Python实现的根据文件名查找数据文件功能示例-创新互联

本文实例讲述了Python实现的根据文件名查找数据文件功能。分享给大家供大家参考,具体如下:

涞水网站建设公司创新互联公司,涞水网站设计制作,有大型网站制作公司丰富经验。已为涞水上千多家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的涞水做网站的公司定做!
#-*- coding: UTF-8 -*-
import os
import shutil
AllFiles=[]
NameFiles=[]
def findFie(filePath):
 pathDir = os.listdir(filePath)
 for allDir in pathDir:
  # print(allDir)
  AllFiles.append(allDir)
  #pass
#filepath = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\71\\71sns'
#copyfile = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\71mtp'
filepath = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\72\\72sns'
copyfile = 'C:\\Users\\IBM_ADMIN\\Desktop\\cognos\\datastage\\71&72\\72mtp'
shutil.rmtree(copyfile)
os.mkdir(copyfile)
findFie(filepath)
def readFile():
 readFile = open('./jobname')
 i = 0
 for eachLine in readFile:
  i= i + 1
  #print(eachLine)
  NameFiles.append(eachLine.replace('\n','')) # 去掉换行符
readFile()
#字符串比较
def doTheCompare():
 for x in NameFiles:
  print(x)
  for y in AllFiles:
   if x == y :
    copyFrom = os.path.join(filepath,x)
    copyTo = os.path.join(copyfile,x)
    shutil.copyfile(copyFrom,copyTo)
   else:
    pass
    #print ("file not find under sns process,thanks .please check with wumi.")
doTheCompare()


分享文章:Python实现的根据文件名查找数据文件功能示例-创新互联
网页路径:http://njwzjz.com/article/dsiocs.html