Python查找当前目录及子目录内所有Excel文件里是否存在目标数字字符demo。
1. 遍历当前目录及所有子目录;
2. 读取所有xls和xlsx文件;
3. 查找目标以四位数字字符为例;
4. 返回信息为文件名,找到的位置信息。
import time
import os
import xlrd
import copy
import pathlib
def getusefile():
#查当前目录下所有xls xlsx文件,返回文件名列表
usefile=[]
excelfile=sorted(pathlib.Path('.').glob('**/*.xls*'))
usefile=[str(tpfile) for tpfile in excelfile]
return copy.deepcopy(usefile)
def rdusefile(fileName,checknum):
#读一个文件,并在文件单元格中查找目标数据,如果找到就返回文件名及数据
data=xlrd.op