Python通过判断Excel表格数据来移动文件

import os
import shutil
import xlrd

excel_path = r"D:\指标.xlsx"
indicator_path = r"D:\IDX_V17"
destination_path = r"D:\IDX"

# 打开excel表格
excel_wb = xlrd.open_workbook(excel_path)
# 打开第一个sheet页
sheet1 = excel_wb.sheet_by_index(0)
# 行数减1,行数根据有值的行来确定
rowNum = sheet1.nrows - 1
idx_version = {}
for i in range(1, rowNum+1):
    print(i, sheet1.cell(i, 5).value)
    idx_version[sheet1.cell(i, 5).value + '.py'] = sheet1.cell(i, 9).value
print(idx_version)
# indicator = open(indicator_path, mode='r', encoding='utf-8')
versionPath = ""
# 遍历文件夹
for item in os.listdir(indicator_path):
    version = idx_version.get(item)
    if version == "基础版":
        versionPath = "Basic"
    elif version == "标准版":
        versionPath = "Standard"
    elif version == "高级版":
        versionPath = "Advanced"

    dest_path = os.path.join(destination_path, versionPath)
    src_path = os.path.join(indicator_path, item)
    # copy文件
    res = shutil.copy(src_path, dest_path)
    print("dest_path:" + dest_path)
    print("src_path:" + src_path)
    print("res:" + res)
    print(item)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值