现有若干个文件,excel内有小于若干个文件文件名,若干个文件excel里也可能没有,需要从若干个文件夹内提取两边共有的文件,并且生产一个新的文件,可以用以下代码操作
import os
import xlrd
import shutil
import hashlib
path = r'C:\Users\10404\PycharmProjects\pythonProject\data'//源文件路径
datanames = os.listdir(path)
name1=[]
for i in datanames:
name1.append(i)
def extract(inpath):
data = xlrd.open_workbook(inpath, encoding_override='utf-8')
table = data.sheets()[0] # 选定表
nrows = table.nrows # 获取行号
ncols = table.ncols # 获取列号
name2 = []
for i in range(1, nrows): # 第0行为表头
alldata = table.row_values(i) # 循环输出excel表中每一行,即所有数据
name2.append(alldata[6]) # 取出表中第二列数据
# print(name2)//
return name2
inpath = r'C:\Users\10404\PycharmProjects\pythonProject\666.xlsx' # excel文件所在路径
name3 = extract(inpath)
for item1 in name1:
for item2 in name3: