马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
下面这张图是我代码跑出来的效果
下面是我的代码import os
import pandas as pd
from pandas import DataFrame
import time
path1 = r'C:\Users\Administrator\Desktop\bat\1224111测试\测试'
path = r'E:\色卡保存\电子色卡\电子色卡\1\扫描文件'
excelname = r'C:\Users\Administrator\Desktop\1224.xls' # 这个改成你要读取的excel名
# path = os.getcwd() # 获取当前目录路径
df = pd.read_excel(excelname)
df.columns = ["a","b","c","d","e","f","g","h","i","j","k"]
enn = 0
cnn = 0
i = 2
for file in os.listdir(path): # 第一层文件夹
folder1_path = os.path.join(path, file)
if os.path.isdir(folder1_path):
folder1_name = file.split('.')[0]
print(folder1_name) # 文件名
createtime = time.ctime(os.path.getctime(folder1_path))
df.loc[i, 'b'] = folder1_name
df.loc[i, 'k'] = createtime
print(createtime)
for file in os.listdir(folder1_path): # 第二层文件夹
folder2_path = os.path.join(folder1_path, file)
folder2_name = file.split('.')[0]
print(folder2_name)
for file in os.listdir(folder2_path):
folder3_name = file.split('.')[0] # 第三层文件夹
print(folder3_name)
if folder3_name == folder2_name: # 判断文件名
folder3_path = os.path.join(folder2_path, file)
df.loc[i, 'c'] = file.split('.')[0]
files1 = os.listdir(folder3_path)
num1 = len(files1)
df.loc[i, 'e'] = num1
# listdir(file_path)
# print(file.split('.')[0])
if file.split('.')[0] == "主图":
folder4_path = os.path.join(folder2_path, file)
folder4_name = file.split('.')[0]
print(folder4_name)
files2 = os.listdir(folder4_path)
num2 = len(files2)
df.loc[i, 'f'] = num2
i = i + 1
DataFrame(df).to_excel('11224.xlsx', sheet_name='Sheet1', index=False, header=True)
可是我想要的效果是下面这张图
这个要怎么改一下,我有点蒙,谢谢 |