从文件夹找到excel,按几分部归类整理好
import os
import openpyxl
from openpyxl import Workbook
from copy import deepcopy
from shutil import copyfile
def num_to_char(num):
"""数字转中文"""
num=str(num)
new_str=""
num_dict={"0":u"零","1":u"一","2":u"二","3":u"三","4":u"四","5":u"五","6":u"六","7":u"七","8":u"八","9":u"九"}
listnum=list(num)
# print(listnum)
shu=[]
for i in listnum:
# print(num_dict[i])
shu.append(num_dict[i])
new_str="".join(shu)
# print(new_str)
return new_str
rootDir = './兰州中通道需重新加载分部分项/'
dirs1 = os.listdir(rootDir)
for dir1 in dirs1:
# print(dir1)
dirs2 = os.listdir(rootDir + dir1 + "/")
for filename in dirs2:
# 遍历五个分部
for i in range(5):
fenBuName=num_to_char(i+1)+'分部'
if fenBuName in filename:
# 判断文件夹是否存在
dir_name = './所有分部/' + fenBuName+'/'
if not os.path.isdir(dir_name):
os.makedirs(dir_name)
source = rootDir + dir1 + "/" + filename
target = dir_name + filename
print(filename)
copyfile(source, target)
目录结构