• 办公自动化15-一次性生成多层目录


    excel里面的目录是这样的:

    生成的目录是这样的

    代码如下:

    import os, sys
    import pandas as pd 
    
    path = 'C:/Users/17360/Desktop/cy/' 
    
    df = pd.read_excel(r'C:Users17360Desktop	est.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) #生成文件夹

    有问题欢迎提问哦~~~^_^

  • 相关阅读:
    GCD 并行子线程
    iOS开发>学无止境
    iOS开发>学无止境
    iOS开发>学无止境
    FMDB使用
    递归
    局部变量与全局变量
    函数式编程与参数
    文件的操作
    集合的操作
  • 原文地址:https://www.cnblogs.com/lizitingxue/p/12623201.html
Copyright © 2020-2023  润新知