标签:div desktop 生成 sys 提问 img idt taf src
excel里面的目录是这样的:
生成的目录是这样的
代码如下:
import os, sys import pandas as pd path = ‘C:/Users/17360/Desktop/cy/‘ df = pd.read_excel(r‘C:\Users\17360\Desktop\test.xlsx‘,sheet_name= ‘Sheet1‘)#将excel表中的文件夹名称读入DataFrame df.head() menu = list(df[‘目录‘]) for lst in menu: print(lst) num = lst.split(‘ ‘)[0]#分条件,生成文件夹
if len(num.split("-")) == 2: file_name = path + str(lst) #文件夹路径 os.mkdir(file_name) #生成文件夹 if len(num.split("-")) == 3: if (len(num.split(‘-‘)[1])+len(num.split(‘-‘)[0])) == 2: pat = re.compile(‘^‘+num[0:3]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])) == 3: pat = re.compile(‘^‘+num[0:4]+‘[^\d]*[\u4e00-\u9fa5]+‘) if len(num.split(‘-‘)[1]) == 2&len(num.split(‘-‘)[0]) == 2: pat = re.compile(‘^‘+num[0:5]+‘[^\d]*[\u4e00-\u9fa5]+‘) for i in menu: tem = pat.findall(i) print(tem) if len(tem)>0: file_name = path +str(tem[0]) + ‘/‘ + str(lst) #文件夹路径 os.mkdir(file_name) #生成文件夹 if len(num.split("-")) == 4: if len(num.split(‘-‘)[1]) == 1: pat = re.compile(‘^‘+num[0:3]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])) == 3: pat = re.compile(‘^‘+num[0:4]+‘[^\d]*[\u4e00-\u9fa5]+‘) if len(num.split(‘-‘)[1]) == 2&len(num.split(‘-‘)[0]) == 2: pat = re.compile(‘^‘+num[0:5]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])+len(num.split(‘-‘)[2])) == 3: pat1 = re.compile(‘^‘+num[0:5]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])+len(num.split(‘-‘)[2])) == 4: pat1 = re.compile(‘^‘+num[0:6]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])+len(num.split(‘-‘)[2])) == 5: pat1 = re.compile(‘^‘+num[0:7]+‘[^\d]*[\u4e00-\u9fa5]+‘) if (len(num.split(‘-‘)[1]) + len(num.split(‘-‘)[0])+len(num.split(‘-‘)[2])) == 6: pat1 = re.compile(‘^‘+num[0:8]+‘[^\d]*[\u4e00-\u9fa5]+‘) for i in menu: tem = pat.findall(i) if len(tem)>0: s1 = tem print(s1) for i in menu: tem1 = pat1.findall(i) if len(tem1)>0: s2 = tem1 print(s2) file_name = path +str(s1[0])+‘/‘+str(s2[0]) + ‘/‘ + str(lst) #文件夹路径 os.mkdir(file_name) #生成文件夹
有问题欢迎提问哦~~~^_^
标签:div desktop 生成 sys 提问 img idt taf src
原文地址:https://www.cnblogs.com/lizitingxue/p/12623201.html